aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp23/lambda-scope8.C
blob: 87ad473238090e89e2a5fde002069962cc6fa32c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// P2036R3 - Change scope of lambda trailing-return-type
// PR c++/102610
// { dg-do compile { target c++23 } }
// { dg-options "-Wshadow" }

void
bad ()
{
  [x=1](int x){};  // { dg-error "declared as a capture" }
  // { dg-warning "shadows a lambda capture" "" { target *-*-* } .-1 }
  [x=1]{ int x; };  // { dg-error "shadows a parameter" }

  auto f = [i = 5] () { int i; return 0; }; // { dg-error "shadows a parameter" }
  auto f2 = [i = 5] <int N> () { int i; return 0; };  // { dg-error "shadows a parameter" }

  // [expr.prim.lambda.capture]/5
  int x = 0;
  auto g = [x](int x) { return 0; };  // { dg-error "declared as a capture" }
  // { dg-warning "shadows a lambda capture" "" { target *-*-* } .-1 }
  auto h = [y = 0]<typename y>(y) { return 0; };  // { dg-error "shadows template parameter" }

  auto l2 = [i = 0, j = i]() -> decltype(i) { // { dg-error "not declared in this scope" }
    return i;
  };
}