File: cxx1y-default-initializer.cpp

package info (click to toggle)
llvm-toolchain-13 1%3A13.0.1-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,418,840 kB
  • sloc: cpp: 5,290,826; ansic: 996,570; asm: 544,593; python: 188,212; objc: 72,027; lisp: 30,291; f90: 25,395; sh: 24,898; javascript: 9,780; pascal: 9,398; perl: 7,484; ml: 5,432; awk: 3,523; makefile: 2,913; xml: 953; cs: 573; fortran: 539
file content (50 lines) | stat: -rw-r--r-- 1,463 bytes parent folder | download | duplicates (21)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// RUN: %clang_cc1 -pedantic -std=c++1y -include %s -include %s -verify %s
// RUN: %clang_cc1 -pedantic -std=c++1y -emit-pch -o %t.1 %s
// RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.1 -emit-pch -o %t.2 %s
// RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.2 -verify %s

// RUN: %clang_cc1 -pedantic -std=c++1y -emit-pch -fpch-instantiate-templates -o %t.1 %s
// RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.1 -emit-pch -fpch-instantiate-templates -o %t.2 %s
// RUN: %clang_cc1 -pedantic -std=c++1y -include-pch %t.2 -verify %s

#ifndef HEADER_1
#define HEADER_1

struct A {
  int x;
  int y = 3;
  int z = x + y;
};
template<typename T> constexpr A make() { return A {}; }
template<typename T> constexpr A make(T t) { return A { t }; }

struct B {
  int z1, z2 = z1;
  constexpr B(int k) : z1(k) {}
};

template<typename T> struct C {
  constexpr C() {}
  T c = T();
  struct U {};
};
// Instantiate C<int> but not the default initializer.
C<int>::U ciu;

#elif !defined(HEADER_2)
#define HEADER_2

// Instantiate the default initializer now, should create an update record.
C<int> ci;

#else

static_assert(A{}.z == 3, "");
static_assert(A{1}.z == 4, "");
static_assert(A{.y = 5}.z == 5, ""); // expected-warning {{C++20}}
static_assert(A{3, .y = 1}.z == 4, ""); // expected-warning {{C99}} expected-note {{here}}
static_assert(make<int>().z == 3, "");
static_assert(make<int>(12).z == 15, "");
static_assert(C<int>().c == 0, "");

#endif