1 /* { dg-options "-Wmisleading-indentation -Wall" } */
2 /* { dg-do compile } */
5 extern int bar (int, int);
15 if (flag
) /* { dg-message "3: ...this 'if' clause, but it is not" } */
17 y
= 2; /* { dg-warning "statement is indented as if it were guarded by..." } */
22 fn_2 (int flag
, int x
, int y
)
24 if (flag
) /* { dg-message "3: ...this 'if' clause, but it is not" } */
25 x
++; y
++; /* { dg-warning "statement is indented as if it were guarded by..." } */
36 else /* { dg-message "3: ...this 'else' clause, but it is not" } */
38 y
= 2; /* { dg-warning "statement is indented as if it were guarded by..." } */
43 fn_4 (double *a
, double *b
, double *c
)
46 while (i
< 10) /* { dg-message "3: ...this 'while' clause, but it is not" } */
48 i
++; /* { dg-warning "statement is indented as if it were guarded by..." } */
52 fn_5 (double *a
, double *b
, double *sum
, double *prod
)
55 for (i
= 0; i
< 10; i
++) /* { dg-output "3: ...this 'for' clause, but it is not" } */
57 prod
[i
] = a
[i
] * b
[i
]; /* { dg-warning "statement is indented as if it were guarded by..." } */
60 /* Based on CVE-2014-1266 aka "goto fail" */
61 int fn_6 (int a
, int b
, int c
)
66 if ((err
= foo (a
)) != 0)
68 if ((err
= foo (b
)) != 0) /* { dg-message "2: ...this 'if' clause, but it is not" } */
70 goto fail
; /* { dg-warning "statement is indented as if it were guarded by..." } */
71 if ((err
= foo (c
)) != 0)
79 int fn_7 (int p
, int q
, int r
, int s
, int t
)
83 if (p
) /* { dg-message "7: ...this 'if' clause, but it is not" } */
84 q
++; r
++; /* { dg-warning "statement is indented as if it were guarded by..." } */
87 return p
+ q
+ r
+ s
+ t
;
90 int fn_8 (int a
, int b
, int c
)
92 /* This should *not* be flagged as misleading indentation. */
93 if (a
) return b
; else return c
;
98 if (flag
) /* { dg-message "3: ...this 'if' clause, but it is not" } */
100 foo (1); /* { dg-warning "statement is indented as if it were guarded by..." } */
103 void fn_10 (int flag
)
105 if (flag
) /* { dg-message "3: ...this 'if' clause, but it is not" } */
111 foo (2); /* { dg-warning "statement is indented as if it were guarded by..." } */
119 if (flagC
) /* { dg-message "7: ...this 'if' clause, but it is not" } */
121 bar (1, 2); /* { dg-warning "statement is indented as if it were guarded by..." } */
127 if (flagB
) /* { dg-message "5: ...this 'if' clause, but it is not" } */
130 bar (1, 2); /* { dg-warning "statement is indented as if it were guarded by..." } */
135 if (flagA
) /* { dg-message "3: ...this 'if' clause, but it is not" } */
139 bar (1, 2); /* { dg-warning "statement is indented as if it were guarded by..." } */
142 #define FOR_EACH(VAR, START, STOP) \
143 for ((VAR) = (START); (VAR) < (STOP); (VAR++)) /* { dg-message "3: ...this 'for' clause, but it is not" } */
148 FOR_EACH (i
, 0, 10) /* { dg-message "3: in expansion of macro" } */
150 bar (i
, i
); /* { dg-warning "statement is indented as if it were guarded by..." } */
154 #define FOR_EACH(VAR, START, STOP) for ((VAR) = (START); (VAR) < (STOP); (VAR++)) /* { dg-message "36: ...this 'for' clause, but it is not" } */
158 FOR_EACH (i
, 0, 10) /* { dg-message "3: in expansion of macro" } */
160 bar (i
, i
); /* { dg-warning "statement is indented as if it were guarded by..." } */
164 void fn_16_spaces (void)
167 for (i
= 0; i
< 10; i
++)
169 if (flagB
) /* { dg-message "7: ...this 'if' clause, but it is not" } */
171 foo (1); /* { dg-warning "statement is indented as if it were guarded by..." } */
174 void fn_16_tabs (void)
177 for (i
= 0; i
< 10; i
++)
179 if (flagB
) /* { dg-message "7: ...this 'if' clause, but it is not" } */
181 foo (1);/* { dg-warning "statement is indented as if it were guarded by..." } */
184 void fn_17_spaces (void)
187 for (i
= 0; i
< 10; i
++) /* { dg-message "3: ...this 'for' clause, but it is not" } */
191 foo (1);/* { dg-warning "statement is indented as if it were guarded by..." } */
194 void fn_17_tabs (void)
197 for (i
= 0; i
< 10; i
++) /* { dg-message "3: ...this 'for' clause, but it is not" } */
201 foo (1);/* { dg-warning "statement is indented as if it were guarded by..." } */
204 void fn_18_spaces (void)
207 for (i
= 0; i
< 10; i
++)
208 while (flagA
) /* { dg-message "5: ...this 'while' clause, but it is not" } */
211 foo (1);/* { dg-warning "statement is indented as if it were guarded by..." } */
214 void fn_18_tabs (void)
217 for (i
= 0; i
< 10; i
++)
218 while (flagA
) /* { dg-message "5: ...this 'while' clause, but it is not" } */
221 foo (1);/* { dg-warning "statement is indented as if it were guarded by..." } */
224 /* This shouldn't lead to a warning. */
225 int fn_19 (void) { if (flagA
) return 1; else return 0; }
227 /* A deeply-nested mixture of spaces and tabs, adapted from
228 c-c++-common/pr60101.c.
229 This should not lead to a warning. */
231 fn_20 (unsigned int l
)
235 for (i
= 0; i
< 10; i
++)
237 unsigned int n0
, n1
, n2
, n3
, n4
, n5
, n6
, n7
, n8
, n9
, n10
, n11
;
239 for (n0
= 0; n0
< l
; n0
++)
240 for (n1
= 0; n1
< l
; n1
++)
241 for (n2
= 0; n2
< l
; n2
++)
242 for (n3
= 0; n3
< l
; n3
++)
243 for (n4
= 0; n4
< l
; n4
++)
244 for (n5
= 0; n5
< l
; n5
++)
245 for (n6
= 0; n6
< l
; n6
++)
246 for (n7
= 0; n7
< l
; n7
++)
247 for (n8
= 0; n8
< l
; n8
++)
248 for (n9
= 0; n9
< l
; n9
++)
249 for (n10
= 0; n10
< l
; n10
++)
250 for (n11
= 0; n11
< l
; n11
++)
260 /* Another nested mix of tabs and spaces that shouldn't lead to a warning,
261 with a preprocessor directive thrown in for good measure
262 (adapted from libgomp/loop.c: gomp_loop_init). */
289 /* The conditionals within the following macros shouldn't be warned about.
290 Adapted from libgomp/driver.c: gomp_load_plugin_for_device. */
303 #define DLSYM_OPT() \
323 /* This shouldn't be warned about. */
324 void fn_23 (void) { foo (0); foo (1); if (flagA
) foo (2); foo (3); foo (4); }
326 /* Code that simply doesn't bother indenting anywhere (e.g. autogenerated
327 code) shouldn't be warned about. */
336 /* Adapted from libiberty/regex.c; an example of a conditional in a
337 macro where the successor statement begins with a macro arg:
341 num = num * 10 + c - '0';
342 ^ this successor statement
344 and hence "num" has a spelling location at the argument of the
345 macro usage site ("lower_bound"), we want the definition of the
346 parameter ("num") for the indentation comparison to be meaninful.
348 This should not generate a misleading indentation warning. */
350 # define GET_UNSIGNED_NUMBER(num) \
358 num = num * 10 + c - '0'; \
362 void fn_25 (int c
, int lower_bound
, int upper_bound
)
364 GET_UNSIGNED_NUMBER (lower_bound
);
366 #undef GET_UNSIGNED_NUMBER
368 /* Example adapted from libdecnumber/decNumber.c:decExpOp that shouldn't
369 trigger a warning. */
373 if (flagB
) foo (0); }
377 /* Ensure that we don't get confused by mixed tabs and spaces; the line
378 "foo (1);" has leading spaces before a tab, but this should not
379 lead to a warning from -Wmisleading-indentation. */
387 /* Example adapted from gcc/cgraph.h:symtab_node::get_availability of
388 a spurious trailing semicolon that shouldn't generate a warning. */
397 /* However, other kinds of spurious semicolons can be a problem. Sadly
398 we don't yet report for the misleading-indented "foo (1);" in the
399 following, due to the spurious semicolon. */
408 /* Adapted from usage site of #ifdef HAVE_cc0. This should not lead
409 to a warning from -Wmisleading-indentation. */
414 #if SOME_CONDITION_THAT_DOES_NOT_HOLD
420 /* This shouldn't lead to a warning. */