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" }
5
6 struct S {};
f1(int x)7 int f1(int x) // { dg-message "shadowed declaration" }
8 {
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;
16 }
17
f2(struct S i,int j)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 };
32 }
33
f3(int i)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 };
40 }
41
42 template <class T>
f4(int i)43 void f4(int i) {
44 [=]{
45 int j = i; // { dg-message "shadowed declaration" }
46 int i; // { dg-warning "shadows a " }
47 i = 1;
48 };
49 }
50
51 template void f4<int>(int);
52