Clang Project

clang_source_code/test/PCH/cxx1z-decomposition.cpp
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 %s -o %t
6// RUN: %clang_cc1 -pedantic -std=c++1z -include-pch %t -verify %s
7
8#ifndef HEADER
9#define HEADER
10
11template<typename T> auto decomp(const T &t) {
12  auto &[a, b] = t;
13  return a + b;
14}
15
16struct Q { int a, b; };
17constexpr int foo(Q &&q) {
18  auto &[a, b] = q;
19  return a * 10 + b;
20}
21
22#else
23
24int arr[2];
25int k = decomp(arr);
26
27static_assert(foo({1, 2}) == 12);
28
29// expected-error@12 {{cannot decompose non-class, non-array type 'const int'}}
30int z = decomp(10); // expected-note {{instantiation of}}
31
32#endif
33