| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-Wshadow=local" } */ |
| 3 |
|
| 4 |
struct Bar { |
| 5 |
}; |
| 6 |
|
| 7 |
struct Bar bar; /* { dg-bogus "shadowed declaration" } */ |
| 8 |
|
| 9 |
int val; /* { dg-bogus "shadowed declaration" } */ |
| 10 |
|
| 11 |
int func1(int x) { /* { dg-bogus "shadowed declaration" } */ |
| 12 |
int val; /* { dg-bogus "shadows a global" } */ |
| 13 |
val = x; |
| 14 |
return val; |
| 15 |
} |
| 16 |
|
| 17 |
int func2(int i) { |
| 18 |
int a = 3; /* { dg-message "shadowed declaration" } */ |
| 19 |
int j; /* { dg-message "shadowed declaration" } */ |
| 20 |
|
| 21 |
for (j = 0; j < i; ++j) { |
| 22 |
int a = j; /* { dg-warning "shadows a previous local" } */ |
| 23 |
int j = a + 1; /* { dg-warning "shadows a previous local" } */ |
| 24 |
func1(j); |
| 25 |
} |
| 26 |
|
| 27 |
return a; |
| 28 |
} |
| 29 |
|
| 30 |
int func3() { |
| 31 |
int bar; /* { dg-bogus "shadows a global" } */ |
| 32 |
float func1 = 0.3; /* { dg-bogus "shadows a global" } */ |
| 33 |
|
| 34 |
if (func1 > 1) |
| 35 |
bar = 2; |
| 36 |
else |
| 37 |
bar = 1; |
| 38 |
return bar; |
| 39 |
} |
| 40 |
|
| 41 |
void func4() { |
| 42 |
struct Bar bar; /* { dg-message "shadowed declaration" } */ |
| 43 |
/* { dg-bogus "shadows a global" "" { target *-*-* } .-1 } */ |
| 44 |
|
| 45 |
if (val) { |
| 46 |
int bar; /* { dg-warning "shadows a previous local" } */ |
| 47 |
func1(bar); |
| 48 |
} |
| 49 |
} |
| 50 |
|