Debian Codegraph @

clang/test/CodeGenCXX/meminit-initializers-odr.cpp

raw
1 // RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
2
3 struct ThisShouldBeCalled {
4 ThisShouldBeCalled() {}
5 };
6
7 template <typename T>
8 struct ThisShouldBeCalledTPL {
9 ThisShouldBeCalledTPL() {}
10 };
11
12 consteval int f () {
13 return 42;
14 }
15
16 struct WithConsteval {
17 WithConsteval(int x = f()) {}
18 };
19
20 template <typename T>
21 struct WithConstevalTPL {
22 WithConstevalTPL(T x = f()) {}
23 };
24
25
26 struct Base {
27 ThisShouldBeCalled y = {};
28 };
29
30 struct S : Base {
31 ThisShouldBeCalledTPL<int> A = {};
32 WithConsteval B = {};
33 WithConstevalTPL<double> C = {};
34 };
35 void Do(S = S{}) {}
36
37 void test() {
38 Do();
39 }
40
41 // CHECK-LABEL: @_ZN18ThisShouldBeCalledC2Ev
42 // CHECK-LABEL: @_ZN21ThisShouldBeCalledTPLIiEC2Ev
43 // CHECK-LABEL: @_ZN13WithConstevalC2Ei
44 // CHECK-LABEL: @_ZN16WithConstevalTPLIdEC2Ed
45
46 namespace check_arrays {
47
48 template <typename T>
49 struct inner {
50 inner() {}
51 };
52
53 struct S {
54 inner<int> a {};
55 };
56
57 class C {
58 S s[1]{};
59 };
60
61 int f() {
62 C c;
63 return 0;
64 }
65
66 // CHECK-LABEL: @_ZN12check_arrays5innerIiEC2Ev
67
68 }
69
70 namespace check_field_inits_in_base_constructors {
71
72 template <typename>
73 struct ShouldBeODRUsed {
74 ShouldBeODRUsed() {}
75 };
76 class k {
77 // The private here is important,
78 // otherwise it would be aggregate initialized.
79 private:
80 ShouldBeODRUsed<k> a = {};
81 };
82
83 struct b {
84 k c{};
85 };
86 void test() { b d; }
87
88 // CHECK-LABEL: @_ZN38check_field_inits_in_base_constructors15ShouldBeODRUsedINS_1kEEC2Ev
89
90 }
91
92 namespace check_referenced_when_defined_in_default_parameter {
93
94 template <typename T>
95 struct Test {
96 Test(auto&&) {}
97 };
98
99 struct Options {
100 Test<bool(bool x)> identity = [](bool x) -> bool { return x; };
101 };
102
103 struct Wrapper {
104 Wrapper(const Options& options = Options());
105 };
106
107 void Func() { Options options; }
108
109 // CHECK-LABEL: @_ZN50check_referenced_when_defined_in_default_parameter7OptionsC2Ev
110 // CHECK-LABEL: @_ZN50check_referenced_when_defined_in_default_parameter4TestIFbbEEC1INS_7Options8identityMUlbE_EEEOT_
111 // CHECK-LABEL: @_ZN50check_referenced_when_defined_in_default_parameter4TestIFbbEEC2INS_7Options8identityMUlbE_EEEOT_
112
113 }
114
115 namespace lambda_body {
116 template <typename a>
117 int templated_func() {
118 return 0;
119 }
120 struct test_body {
121 int mem = templated_func<int>();
122 };
123 struct test_capture {
124 int mem = templated_func<double>();
125 };
126
127 struct S {
128 int a = [_ = test_capture{}] { (void)test_body{}; return 0;}();
129 };
130
131 void test() {
132 S s;
133 }
134
135 // CHECK-LABEL: define{{.*}} @_ZN11lambda_body14templated_funcIdEEiv
136 // CHECK-LABEL: define{{.*}} @_ZNK11lambda_body1S1aMUlvE_clEv
137 // CHECK-LABEL: define{{.*}} @_ZN11lambda_body14templated_funcIiEEiv
138
139
140 }