1 /* $NetBSD: fmt_else_comment.c,v 1.6 2023/06/23 20:44:51 rillig Exp $ */ 2 3 /* 4 * Tests for comments after 'if (expr)' and 'else'. Before 2023-05-11, if the 5 * option '-br' was given (or rather, if '-bl' was not given), indent looked 6 * ahead to the following significant token to see whether it was a '{', it 7 * then moved the comments after the '{'. This token swapping was error-prone 8 * and thus removed. 9 * 10 * See also: 11 * FreeBSD r303484 12 * FreeBSD r309342 13 */ 14 15 /* 16 * Before 2023-05-11, the two 'if' statements below exercised two different 17 * code paths, even though they look very similar. 18 */ 19 //indent input 20 void t(void) { 21 if (1) /* a */ int a; else /* b */ int b; 22 23 if (1) /* a */ 24 int a; 25 else /* b */ 26 int b; 27 } 28 //indent end 29 30 //indent run 31 void 32 t(void) 33 { 34 if (1) /* a */ 35 int a; 36 else /* b */ 37 int b; 38 39 if (1) /* a */ 40 int a; 41 else /* b */ 42 int b; 43 } 44 //indent end 45 46 47 //indent input 48 void t(void) { 49 if (1) { 50 51 } 52 53 54 55 /* Old indent would remove the 3 blank lines above, awaiting "else". */ 56 // $ 'Old' means something before 2019. 57 58 if (1) { 59 int a; 60 } 61 62 63 else if (0) { 64 int b; 65 } 66 /* test */ 67 else 68 ; 69 70 if (1) 71 ; 72 else /* Old indent would get very confused here */ 73 // $ 'Old' means something before 2019. 74 /* We also mustn't assume that there's only one comment */ 75 /* before the left brace. */ 76 { 77 78 79 } 80 } 81 //indent end 82 83 //indent run -bl 84 void 85 t(void) 86 { 87 if (1) 88 { 89 90 } 91 92 93 94 /* 95 * Old indent would remove the 3 blank lines above, awaiting "else". 96 */ 97 98 if (1) 99 { 100 int a; 101 } 102 103 104 else if (0) 105 { 106 int b; 107 } 108 /* test */ 109 else 110 ; 111 112 if (1) 113 ; 114 else /* Old indent would get very confused here */ 115 /* We also mustn't assume that there's only one comment */ 116 /* before the left brace. */ 117 { 118 119 120 } 121 } 122 //indent end 123