PR tree-optimization/86401
[official-gcc.git] / gcc / testsuite / c-c++-common / Wmisleading-indentation-3.c
blob870ba720c5f143aa3fb1040ee61e04b801a558b9
1 /* Verify -Wmisleading-indentation with source-printing.
2 This is a subset of Wmisleading-indentation.c. */
4 /* { dg-options "-Wmisleading-indentation -fdiagnostics-show-caret" } */
5 /* { dg-do compile } */
7 extern int foo (int);
8 extern int bar (int, int);
9 extern int flagA;
10 extern int flagB;
11 extern int flagC;
12 extern int flagD;
14 void
15 fn_5 (double *a, double *b, double *sum, double *prod)
17 int i = 0;
18 for (i = 0; i < 10; i++) /* { dg-warning "3: this 'for' clause does not guard..." } */
19 sum[i] = a[i] * b[i];
20 prod[i] = a[i] * b[i]; /* { dg-message "5: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'" } */
21 /* { dg-begin-multiline-output "" }
22 for (i = 0; i < 10; i++)
23 ^~~
24 { dg-end-multiline-output "" } */
25 /* { dg-begin-multiline-output "" }
26 prod[i] = a[i] * b[i];
27 ^~~~
28 { dg-end-multiline-output "" } */
31 /* Based on CVE-2014-1266 aka "goto fail" */
32 int fn_6 (int a, int b, int c)
34 int err;
36 /* ... */
37 if ((err = foo (a)) != 0)
38 goto fail;
39 if ((err = foo (b)) != 0) /* { dg-message "2: this 'if' clause does not guard..." } */
40 goto fail;
41 goto fail; /* { dg-message "3: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'" } */
42 if ((err = foo (c)) != 0)
43 goto fail;
44 /* ... */
46 /* { dg-begin-multiline-output "" }
47 if ((err = foo (b)) != 0)
49 { dg-end-multiline-output "" } */
50 /* { dg-begin-multiline-output "" }
51 goto fail;
52 ^~~~
53 { dg-end-multiline-output "" } */
55 fail:
56 return err;
59 #define FOR_EACH(VAR, START, STOP) \
60 for ((VAR) = (START); (VAR) < (STOP); (VAR++)) /* { dg-warning "3: this 'for' clause does not guard..." } */
62 void fn_14 (void)
64 int i;
65 FOR_EACH (i, 0, 10) /* { dg-message "in expansion of macro .FOR_EACH." } */
66 foo (i);
67 bar (i, i); /* { dg-message "5: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'" } */
69 /* { dg-begin-multiline-output "" }
70 for ((VAR) = (START); (VAR) < (STOP); (VAR++))
71 ^~~
72 { dg-end-multiline-output "" } */
73 /* { dg-begin-multiline-output "" }
74 FOR_EACH (i, 0, 10)
75 ^~~~~~~~
76 { dg-end-multiline-output "" } */
77 /* { dg-begin-multiline-output "" }
78 bar (i, i);
79 ^~~
80 { dg-end-multiline-output "" } */
82 #undef FOR_EACH