Debian Codegraph @

gcc/testsuite/g++.dg/warn/Wshadow-local-2.C

raw
1 /* { dg-do compile } */
2 /* { dg-options -Wshadow=local } */
3
4 class Bar {
5 };
6
7 class ChildBar : public Bar {
8 };
9
10 Bar bar; // { dg-bogus "shadowed declaration" }
11
12 class Foo {
13 private:
14 int val;
15
16 public:
17 int func1(int x) {
18 int val; // { dg-bogus "shadows a member" }
19 val = x;
20 return val;
21 }
22
23 int func2(int i) { // { dg-message "shadowed declaration is here" }
24 int a = 3; // { dg-message "shadowed declaration is here" }
25
26 for (int i = 0; i < 5; ++i) { // { dg-warning "shadows a parameter" }
27 for (int i = 0; i < 3; ++i) { // { dg-warning "shadows a previous local" }
28 int a = i; // { dg-warning "shadows a previous local" }
29 func1(a);
30 }
31 }
32
33 return a;
34 }
35
36 int func3() {
37 int bar; // { dg-bogus "shadows a global" }
38 float func1 = 0.3; // { dg-bogus "shadows a member" }
39 int f = 5; // { dg-message "shadowed declaration is here" }
40
41 if (func1 > 1) {
42 float f = 2.0; // { dg-warning "shadows a previous local" }
43 bar = f;
44 }
45 else
46 bar = 1;
47 return bar;
48 }
49
50 void func4() {
51 Bar *bar; // { dg-message "shadowed declaration is here" }
52 ChildBar *cbp; // { dg-message "shadowed declaration is here" }
53 Bar *bp; // { dg-message "shadowed declaration is here" }
54 if (val) {
55 int bar; // { dg-warning "shadows a previous local" }
56 Bar *cbp; // { dg-warning "shadows a previous local" }
57 ChildBar *bp; // { dg-warning "shadows a previous local" }
58 func1(bar);
59 }
60 }
61 };
62
63 // { dg-message "shadowed declaration is here" "" { target *-*-* } 26 }