1 // RUN: %clang_cc1 -pedantic -std=c++1y -include %s -include %s -verify %s
2 // RUN: %clang_cc1 -pedantic -std=c++1y -emit-pch -o %t.1 %s
3 // RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.1 -emit-pch -o %t.2 %s
4 // RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.2 -verify %s
5
6 // RUN: %clang_cc1 -pedantic -std=c++1y -emit-pch -fpch-instantiate-templates -o %t.1 %s
7 // RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.1 -emit-pch -fpch-instantiate-templates -o %t.2 %s
8 // RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.2 -verify %s
9
10 #ifndef HEADER_1
11 #define HEADER_1
12
13 struct A {
14 int x;
15 int y = 3;
16 int z = x + y;
17 };
make()18 template<typename T> constexpr A make() { return A {}; }
make(T t)19 template<typename T> constexpr A make(T t) { return A { t }; }
20
21 struct B {
22 int z1, z2 = z1;
BB23 constexpr B(int k) : z1(k) {}
24 };
25
26 template<typename T> struct C {
CC27 constexpr C() {}
28 T c = T();
29 struct U {};
30 };
31 // Instantiate C<int> but not the default initializer.
32 C<int>::U ciu;
33
34 #elif !defined(HEADER_2)
35 #define HEADER_2
36
37 // Instantiate the default initializer now, should create an update record.
38 C<int> ci;
39
40 #else
41
42 static_assert(A{}.z == 3, "");
43 static_assert(A{1}.z == 4, "");
44 static_assert(A{.y = 5}.z == 5, ""); // expected-warning {{C++20}}
45 static_assert(A{3, .y = 1}.z == 4, ""); // expected-warning {{C99}} expected-note {{here}}
46 static_assert(make<int>().z == 3, "");
47 static_assert(make<int>(12).z == 15, "");
48 static_assert(C<int>().c == 0, "");
49
50 #endif
51