Clang Project

clang_source_code/test/PCH/cxx1y-default-initializer.cpp
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#ifndef HEADER_1
7#define HEADER_1
8
9struct A {
10  int x;
11  int y = 3;
12  int z = x + y;
13};
14template<typename T> constexpr A make() { return A {}; }
15template<typename T> constexpr A make(T t) { return A { t }; }
16
17struct B {
18  int z1, z2 = z1;
19  constexpr B(int k) : z1(k) {}
20};
21
22template<typename T> struct C {
23  constexpr C() {}
24  T c = T();
25  struct U {};
26};
27// Instantiate C<int> but not the default initializer.
28C<int>::U ciu;
29
30#elif !defined(HEADER_2)
31#define HEADER_2
32
33// Instantiate the default initializer now, should create an update record.
34C<int> ci;
35
36#else
37
38static_assert(A{}.z == 3, "");
39static_assert(A{1}.z == 4, "");
40static_assert(A{.y = 5}.z == 5, ""); // expected-warning {{C99}}
41static_assert(A{3, .y = 1}.z == 4, ""); // expected-warning {{C99}}
42static_assert(make<int>().z == 3, "");
43static_assert(make<int>(12).z == 15, "");
44static_assert(C<int>().c == 0, "");
45
46#endif
47