[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / PCH / cxx1y-init-captures.cpp
blobc19dd90ac90be63c3d354a1298f2d55e3c84601d
1 // No PCH:
2 // RUN: %clang_cc1 -pedantic -std=c++1y -include %s -verify %s
3 //
4 // With PCH:
5 // RUN: %clang_cc1 -pedantic -std=c++1y -emit-pch %s -o %t
6 // RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t -verify %s
8 // RUN: %clang_cc1 -pedantic -std=c++1y -emit-pch -fpch-instantiate-templates %s -o %t
9 // RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t -verify %s
11 #ifndef HEADER
12 #define HEADER
14 auto counter = [a(0)] () mutable { return a++; };
15 int x = counter();
17 template<typename T> void f(T t) {
18 [t(t)] { int n = t; } ();
21 #else
23 int y = counter();
25 void g() {
26 f(0); // ok
27 // expected-error@18 {{lvalue of type 'const char *const'}}
28 // expected-note@18 {{substituting into a lambda}}
29 f("foo"); // expected-note {{here}}
32 #endif