File: meminit-initializers-odr.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (140 lines) | stat: -rw-r--r-- 2,618 bytes parent folder | download | duplicates (12)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s

struct ThisShouldBeCalled {
    ThisShouldBeCalled() {}
};

template <typename T>
struct ThisShouldBeCalledTPL {
    ThisShouldBeCalledTPL() {}
};

consteval int f () {
    return 42;
}

struct WithConsteval {
    WithConsteval(int x = f()) {}
};

template <typename T>
struct WithConstevalTPL {
    WithConstevalTPL(T x = f()) {}
};


struct Base {
    ThisShouldBeCalled y = {};
};

struct S : Base {
    ThisShouldBeCalledTPL<int> A =  {};
    WithConsteval B = {};
    WithConstevalTPL<double> C = {};
};
void Do(S = S{}) {}

void test() {
    Do();
}

// CHECK-LABEL: @_ZN18ThisShouldBeCalledC2Ev
// CHECK-LABEL: @_ZN21ThisShouldBeCalledTPLIiEC2Ev
// CHECK-LABEL: @_ZN13WithConstevalC2Ei
// CHECK-LABEL: @_ZN16WithConstevalTPLIdEC2Ed

namespace check_arrays {

template <typename T>
struct inner {
    inner() {}
};

struct S {
   inner<int> a {};
};

class C {
    S s[1]{};
};

int f() {
    C c;
    return 0;
}

// CHECK-LABEL: @_ZN12check_arrays5innerIiEC2Ev

}

namespace check_field_inits_in_base_constructors {

template <typename>
struct ShouldBeODRUsed {
  ShouldBeODRUsed() {}
};
class k {
// The private here is important,
// otherwise it would be aggregate initialized.
private:
  ShouldBeODRUsed<k> a = {};
};

struct b {
  k c{};
};
void test() { b d; }

// CHECK-LABEL: @_ZN38check_field_inits_in_base_constructors15ShouldBeODRUsedINS_1kEEC2Ev

}

namespace check_referenced_when_defined_in_default_parameter {

template <typename T>
struct Test {
    Test(auto&&) {}
};

struct Options {
    Test<bool(bool x)> identity = [](bool x) -> bool { return x; };
};

struct Wrapper {
  Wrapper(const Options& options = Options());
};

void Func() { Options options; }

// CHECK-LABEL: @_ZN50check_referenced_when_defined_in_default_parameter7OptionsC2Ev
// CHECK-LABEL: @_ZN50check_referenced_when_defined_in_default_parameter4TestIFbbEEC1INS_7Options8identityMUlbE_EEEOT_
// CHECK-LABEL: @_ZN50check_referenced_when_defined_in_default_parameter4TestIFbbEEC2INS_7Options8identityMUlbE_EEEOT_

}

namespace lambda_body {
template <typename a>
int templated_func() {
    return 0;
}
struct test_body {
  int mem = templated_func<int>();
};
struct test_capture {
  int mem = templated_func<double>();
};

struct S {
  int a = [_ = test_capture{}] { (void)test_body{}; return 0;}();
};

void test() {
    S s;
}

// CHECK-LABEL: define{{.*}} @_ZN11lambda_body14templated_funcIdEEiv
// CHECK-LABEL: define{{.*}} @_ZNK11lambda_body1S1aMUlvE_clEv
// CHECK-LABEL: define{{.*}} @_ZN11lambda_body14templated_funcIiEEiv


}