Merged revisions 208012,208018-208019,208021,208023-208030,208033,208037,208040-20804...
[official-gcc.git] / main / gcc / testsuite / g++.dg / warn / Wshadow-6.C
blob9c2e8b894606fb10d1e881d124f898e82cf32f37
1 // Test the declaration of nested lambda function shadows
2 // a parameter or previous local.
3 // { dg-do compile { target c++11 } }
4 // { dg-options "-Wshadow" }
6 struct S {};
7 int f1(int x)   // { dg-message "shadowed declaration" }
9  int t = 0;
10  int m = 0;     // { dg-message "shadowed declaration" }
11  [&t] (int x) { // { dg-warning "shadows a parameter" }
12    int m = 1;   // { dg-warning "shadows a previous local" }
13    t = t + x + m;
14  };
15  return t;
18 void f2(struct S i, int j) {
19   struct A {
20     struct S x;
21     void g(struct S i) { // { dg-message "shadowed declaration" }
22           struct S x;    // { dg-warning "shadows a member of" }
23           struct S y;    // { dg-message "shadowed declaration" }
24           int t;
25            [&t](struct S i){   // { dg-warning "shadows a parameter" }
26                  int j = 1;    // { dg-bogus "shadows" }
27                  struct S y;   // { dg-warning "shadows a previous local" }
28                  t = j;
29            };
30     }
31   };
34 void f3(int i) {
35  [=]{
36    int j = i;                   // { dg-message "shadowed declaration" }
37    int i;                       // { dg-warning "shadows a lambda capture" }
38    i = 1;
39  };
42 template <class T>
43 void f4(int i) {
44  [=]{
45    int j = i;                   // { dg-message "shadowed declaration" }
46    int i;                       // { dg-warning "shadows a lambda capture" }
47    i = 1;
48  };
51 template void f4<int>(int);