[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / PCH / cxx1z-decomposition.cpp
blob914ce80c550d1d2ccb188c0f0d91e295d091d8b8
1 // No PCH:
2 // RUN: %clang_cc1 -pedantic -std=c++1z -include %s -verify %s
3 //
4 // With PCH:
5 // RUN: %clang_cc1 -pedantic -std=c++1z -emit-pch -fallow-pch-with-compiler-errors %s -o %t
6 // RUN: %clang_cc1 -pedantic -std=c++1z -include-pch %t -fallow-pch-with-compiler-errors -verify %s
8 // RUN: %clang_cc1 -pedantic -std=c++1z -emit-pch -fallow-pch-with-compiler-errors -fpch-instantiate-templates %s -o %t
9 // RUN: %clang_cc1 -pedantic -std=c++1z -include-pch %t -fallow-pch-with-compiler-errors -verify %s
11 #ifndef HEADER
12 #define HEADER
14 template<typename T> auto decomp(const T &t) {
15 auto &[a, b] = t;
16 return a + b;
19 struct Q { int a, b; };
20 constexpr int foo(Q &&q) {
21 auto &[a, b] = q;
22 return a * 10 + b;
25 auto [noinit]; // expected-error{{decomposition declaration '[noinit]' requires an initializer}}
27 #else
29 int arr[2];
30 int k = decomp(arr);
32 static_assert(foo({1, 2}) == 12);
34 // expected-error@15 {{cannot decompose non-class, non-array type 'const int'}}
35 int z = decomp(10); // expected-note {{instantiation of}}
37 #endif