1 /* { dg-do compile } */ 2 /* { dg-options -Wshadow=compatible-local } */ 3 4 class Bar { 5 }; 6 7 class ChildBar : public Bar { 8 }; 9 10 Bar bar; 11 12 class Foo { 13 private: 14 int val; 15 16 public: func1(int x)17 int func1(int x) { 18 int val; 19 val = x; 20 return val; 21 } 22 func2(int i)23 int func2(int i) { // { dg-message "note: shadowed declaration is here" } 24 int a = 3; // { dg-message "note: 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 func3()36 int func3() { 37 int bar; 38 float func1 = 0.3; 39 int f = 5; // { dg-message "note: 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 func4()50 void func4() { 51 Bar *bar; // { dg-bogus "shadowed declaration" } 52 ChildBar *cbp; // { dg-bogus "shadowed declaration" } 53 Bar *bp; // { dg-message "note: shadowed declaration is here" } 54 if (val) { 55 int bar; // { dg-bogus "shadows a previous local" } 56 Bar *cbp; // { dg-bogus "shadows a previous local" } 57 ChildBar *bp; // { dg-warning "shadows a previous local" } 58 func1(bar); 59 } 60 } 61 }; 62 63 // { dg-message "note: shadowed declaration" "" { target *-*-* } 26 } 64