Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr21xx.cpp
bloba1b8fe3f2a9be953cfbf9c1d7b92f284d474c108
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
8 #if __cplusplus < 201103L
9 // expected-error@+1 {{variadic macro}}
10 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
11 #endif
13 namespace dr2100 { // dr2100: 12
14 template<const int *P, bool = true> struct X {};
15 template<typename T> struct A {
16 static const int n = 1;
17 int f() {
18 return X<&n>::n; // ok, value-dependent
20 int g() {
21 static const int n = 2;
22 return X<&n>::n; // ok, value-dependent
23 #if __cplusplus < 201702L
24 // expected-error@-2 {{does not have linkage}} expected-note@-3 {{here}}
25 #endif
28 template<const int *P> struct X<P> {
29 #if __cplusplus < 201103L
30 static const int n = 0;
31 #else
32 static const int n = *P;
33 #endif
35 int q = A<int>().f() + A<int>().g();
37 // Corresponding constructs where the address is not taken are not
38 // value-dependent.
39 template<int N, bool = true> struct Y {};
40 template<typename T> struct B {
41 static const int n = 1;
42 int f() {
43 return Y<n>::declared_later; // expected-error {{no member named 'declared_later'}}
45 int g() {
46 static const int n = 2;
47 return Y<n>::declared_later; // expected-error {{no member named 'declared_later'}}
50 template<int N> struct Y<N> {
51 static const int declared_later = 0;
55 namespace dr2103 { // dr2103: yes
56 void f() {
57 int a;
58 int &r = a; // expected-note {{here}}
59 struct Inner {
60 void f() {
61 int &s = r; // expected-error {{enclosing function}}
62 (void)s;
68 namespace dr2120 { // dr2120: 7
69 struct A {};
70 struct B : A {};
71 struct C { A a; };
72 struct D { C c[5]; };
73 struct E : B { D d; };
74 static_assert(__is_standard_layout(B), "");
75 static_assert(__is_standard_layout(D), "");
76 static_assert(!__is_standard_layout(E), "");
79 namespace dr2126 { // dr2126: 12
80 #if __cplusplus >= 201103L
81 struct A { int n; };
83 const A &a = {1}; // const temporary
84 A &b = (A &)(const A &)A{1}; // const temporary
85 A &&c = (A &&)(const A &)A{1}; // const temporary
87 A &&d = {1}; // non-const temporary expected-note {{here}}
88 const A &e = (A &)(A &&) A{1}; // non-const temporary expected-note {{here}}
89 A &&f = (A &&)(A &&) A{1}; // non-const temporary expected-note {{here}}
91 constexpr const A &g = {1}; // const temporary
92 constexpr A &&h = {1}; // non-const temporary expected-note {{here}}
94 struct B { const A &a; };
95 B i = {{1}}; // extending decl not usable in constant expr expected-note {{here}}
96 const B j = {{1}}; // extending decl not usable in constant expr expected-note {{here}}
97 constexpr B k = {{1}}; // extending decl usable in constant expr
99 static_assert(a.n == 1, "");
100 static_assert(b.n == 1, "");
101 static_assert(c.n == 1, "");
102 static_assert(d.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
103 static_assert(e.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
104 static_assert(f.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
105 static_assert(g.n == 1, "");
106 static_assert(h.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
107 static_assert(i.a.n == 1, ""); // expected-error {{constant}} expected-note {{read of non-constexpr variable}}
108 static_assert(j.a.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
109 static_assert(k.a.n == 1, "");
110 #endif
113 namespace dr2140 { // dr2140: 9
114 #if __cplusplus >= 201103L
115 union U { int a; decltype(nullptr) b; };
116 constexpr int *test(U u) {
117 return u.b;
119 static_assert(!test({123}), "u.b should be valid even when b is inactive");
120 #endif
123 namespace dr2141 { // dr2141: 17
124 struct A{};
126 template <typename T>
127 struct B{};
129 void foo() {
130 struct A *b = (1 == 1) ? new struct A : new struct A;
131 struct S *a = (1 == 1) ? new struct S : new struct S; // expected-error 2{{allocation of incomplete type}} // expected-note 2{{forward}}
133 #if __cplusplus >= 201103L
134 A *aa = new struct A{};
135 B<int> *bb = new struct B<int>{};
136 (void)new struct C{}; // expected-error {{allocation of incomplete type }} // expected-note {{forward}}
138 struct A *c = (1 == 1) ? new struct A {} : new struct A {};
140 alignof(struct D{}); // expected-error {{cannot be defined in a type specifier}}
141 #endif
143 sizeof(struct E{}); // expected-error {{cannot be defined in a type specifier}}
148 namespace dr2157 { // dr2157: 11
149 #if __cplusplus >= 201103L
150 enum E : int;
151 struct X {
152 enum dr2157::E : int(); // expected-error {{only allows ':' in member enumeration declaration to introduce a fixed underlying type}}
154 #endif
157 // dr2165: na
159 namespace dr2170 { // dr2170: 9
160 #if __cplusplus >= 201103L
161 void f() {
162 constexpr int arr[3] = {1, 2, 3}; // expected-note {{here}}
163 struct S {
164 int get(int n) { return arr[n]; }
165 const int &get_ref(int n) { return arr[n]; } // expected-error {{enclosing function}}
166 // FIXME: expected-warning@-1 {{reference to stack}}
169 #endif
172 namespace dr2171 { // dr2171: 15
173 #if __cplusplus >= 201103L
175 struct NonConstCopy {
176 NonConstCopy(NonConstCopy &) = default;
177 NonConstCopy &operator=(NonConstCopy &) = default;
180 static_assert(__has_trivial_copy(NonConstCopy), "");
181 static_assert(__is_trivially_constructible(NonConstCopy, NonConstCopy &), "");
182 static_assert(!__is_trivially_constructible(NonConstCopy, NonConstCopy), "");
183 static_assert(!__is_trivially_constructible(NonConstCopy, const NonConstCopy &), "");
184 static_assert(!__is_trivially_constructible(NonConstCopy, NonConstCopy &&), "");
186 static_assert(__has_trivial_assign(NonConstCopy), "");
187 static_assert(__is_trivially_assignable(NonConstCopy &, NonConstCopy &), "");
188 static_assert(!__is_trivially_assignable(NonConstCopy &, const NonConstCopy &), "");
189 static_assert(!__is_trivially_assignable(NonConstCopy &, NonConstCopy), "");
190 static_assert(!__is_trivially_assignable(NonConstCopy &, NonConstCopy &&), "");
191 static_assert(__is_trivially_assignable(NonConstCopy &&, NonConstCopy &), "");
192 static_assert(!__is_trivially_assignable(NonConstCopy &&, const NonConstCopy &), "");
193 static_assert(!__is_trivially_assignable(NonConstCopy &&, NonConstCopy), "");
194 static_assert(!__is_trivially_assignable(NonConstCopy &&, NonConstCopy &&), "");
196 #endif
197 } // namespace dr2171
199 namespace dr2180 { // dr2180: yes
200 class A {
201 A &operator=(const A &); // expected-note 0-2{{here}}
202 A &operator=(A &&); // expected-note 0-2{{here}} expected-error 0-1{{extension}}
205 struct B : virtual A {
206 B &operator=(const B &);
207 B &operator=(B &&); // expected-error 0-1{{extension}}
208 virtual void foo() = 0;
210 #if __cplusplus < 201103L
211 B &B::operator=(const B&) = default; // expected-error {{private member}} expected-error {{extension}} expected-note {{here}}
212 B &B::operator=(B&&) = default; // expected-error {{private member}} expected-error 2{{extension}} expected-note {{here}}
213 #else
214 B &B::operator=(const B&) = default; // expected-error {{would delete}} expected-note@-9{{inaccessible copy assignment}}
215 B &B::operator=(B&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
216 #endif
219 namespace dr2199 { // dr2199: 3.8
220 // NB: reusing part of dr407 test
221 namespace A {
222 struct S {};
224 namespace B {
225 typedef int S;
227 namespace E {
228 typedef A::S S;
229 using A::S;
230 struct S s;
232 namespace F {
233 typedef A::S S;
235 namespace G {
236 using namespace A;
237 using namespace F;
238 struct S s;
240 namespace H {
241 using namespace F;
242 using namespace A;
243 struct S s;