| 1 |
/* Verify -Wmisleading-indentation with source-printing. |
| 2 |
This is a subset of Wmisleading-indentation.c. */ |
| 3 |
|
| 4 |
/* { dg-options "-Wmisleading-indentation -fdiagnostics-show-caret" } */ |
| 5 |
/* { dg-do compile } */ |
| 6 |
|
| 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; |
| 13 |
|
| 14 |
void |
| 15 |
fn_5 (double *a, double *b, double *sum, double *prod) |
| 16 |
{ |
| 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 "" } */ |
| 29 |
} |
| 30 |
|
| 31 |
/* Based on CVE-2014-1266 aka "goto fail" */ |
| 32 |
int fn_6 (int a, int b, int c) |
| 33 |
{ |
| 34 |
int err; |
| 35 |
|
| 36 |
/* ... */ |
| 37 |
if ((err = foo (a)) != 0) |
| 38 |
goto fail; |
| 39 |
if ((err = foo (b)) != 0) /* { dg-message "9: this 'if' clause does not guard..." } */ |
| 40 |
goto fail; |
| 41 |
goto fail; /* { dg-message "17: ...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 |
/* ... */ |
| 45 |
|
| 46 |
/* { dg-begin-multiline-output "" } |
| 47 |
if ((err = foo (b)) != 0) |
| 48 |
^~ |
| 49 |
{ dg-end-multiline-output "" } */ |
| 50 |
/* { dg-begin-multiline-output "" } |
| 51 |
goto fail; |
| 52 |
^~~~ |
| 53 |
{ dg-end-multiline-output "" } */ |
| 54 |
|
| 55 |
fail: |
| 56 |
return err; |
| 57 |
} |
| 58 |
|
| 59 |
#define FOR_EACH(VAR, START, STOP) \ |
| 60 |
for ((VAR) = (START); (VAR) < (STOP); (VAR++)) /* { dg-warning "3: this 'for' clause does not guard..." } */ |
| 61 |
|
| 62 |
void fn_14 (void) |
| 63 |
{ |
| 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'" } */ |
| 68 |
|
| 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 "" } */ |
| 81 |
} |
| 82 |
#undef FOR_EACH |