Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CXX / expr / expr.prim / expr.prim.lambda / p13.cpp
blob0635a01466afb52d2f0c8787f73d47c62f491078
1 // RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -Wno-c++14-extensions -verify
2 // RUN: %clang_cc1 -std=c++17 %s -Wunused -Wno-unused-lambda-capture -Wno-c++14-extensions -verify
5 const int global = 0;
7 void f2() {
8 int i = 1;
9 void g1(int = ([i]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
10 void g2(int = ([i]{ return 0; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
11 void g3(int = ([=]{ return i; })()); // expected-error{{lambda expression in default argument cannot capture any entity}}
12 void g4(int = ([=]{ return 0; })());
13 void g5(int = ([]{ return sizeof i; })());
14 void g6(int = ([x=1, y = global, &z = global]{ return x; })());
15 void g7(int = ([x=i, &y=i]{ return x; })()); // expected-error 2{{default argument references local variable 'i' of enclosing function}}
18 #if __cplusplus >= 201703L
19 int global_array[] = { 1, 2 };
20 auto [ga, gb] = global_array;
22 void structured_bindings() {
23 int array[] = { 1, 2 };
24 auto [a, b] = array;
25 void func(int c = [x = a, &xref = a, y = ga, &yref = ga] { return x; }()); // expected-error 2{{default argument references local variable 'a' of enclosing function}}
27 #endif
29 namespace lambda_in_default_args {
30 int f(int = [] () -> int { int n; return ++n; } ());
31 template<typename T> T g(T = [] () -> T { T n; return ++n; } ());
32 int k = f() + g<int>();