[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / CXX / drs / dr21xx.cpp
blobbd6f8b7cb6e68465b8ef0cb625b403db13254963
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 dr2157 { // dr2157: 11
124 #if __cplusplus >= 201103L
125 enum E : int;
126 struct X {
127 enum dr2157::E : int(); // expected-error {{only allows ':' in member enumeration declaration to introduce a fixed underlying type}}
129 #endif
132 // dr2165: na
134 namespace dr2170 { // dr2170: 9
135 #if __cplusplus >= 201103L
136 void f() {
137 constexpr int arr[3] = {1, 2, 3}; // expected-note {{here}}
138 struct S {
139 int get(int n) { return arr[n]; }
140 const int &get_ref(int n) { return arr[n]; } // expected-error {{enclosing function}}
141 // FIXME: expected-warning@-1 {{reference to stack}}
144 #endif
147 namespace dr2171 { // dr2171: 15
148 #if __cplusplus >= 201103L
150 struct NonConstCopy {
151 NonConstCopy(NonConstCopy &) = default;
152 NonConstCopy &operator=(NonConstCopy &) = default;
155 static_assert(__has_trivial_copy(NonConstCopy), "");
156 static_assert(__is_trivially_constructible(NonConstCopy, NonConstCopy &), "");
157 static_assert(!__is_trivially_constructible(NonConstCopy, NonConstCopy), "");
158 static_assert(!__is_trivially_constructible(NonConstCopy, const NonConstCopy &), "");
159 static_assert(!__is_trivially_constructible(NonConstCopy, NonConstCopy &&), "");
161 static_assert(__has_trivial_assign(NonConstCopy), "");
162 static_assert(__is_trivially_assignable(NonConstCopy &, NonConstCopy &), "");
163 static_assert(!__is_trivially_assignable(NonConstCopy &, const NonConstCopy &), "");
164 static_assert(!__is_trivially_assignable(NonConstCopy &, NonConstCopy), "");
165 static_assert(!__is_trivially_assignable(NonConstCopy &, NonConstCopy &&), "");
166 static_assert(__is_trivially_assignable(NonConstCopy &&, NonConstCopy &), "");
167 static_assert(!__is_trivially_assignable(NonConstCopy &&, const NonConstCopy &), "");
168 static_assert(!__is_trivially_assignable(NonConstCopy &&, NonConstCopy), "");
169 static_assert(!__is_trivially_assignable(NonConstCopy &&, NonConstCopy &&), "");
171 #endif
172 } // namespace dr2171
174 namespace dr2180 { // dr2180: yes
175 class A {
176 A &operator=(const A &); // expected-note 0-2{{here}}
177 A &operator=(A &&); // expected-note 0-2{{here}} expected-error 0-1{{extension}}
180 struct B : virtual A {
181 B &operator=(const B &);
182 B &operator=(B &&); // expected-error 0-1{{extension}}
183 virtual void foo() = 0;
185 #if __cplusplus < 201103L
186 B &B::operator=(const B&) = default; // expected-error {{private member}} expected-error {{extension}} expected-note {{here}}
187 B &B::operator=(B&&) = default; // expected-error {{private member}} expected-error 2{{extension}} expected-note {{here}}
188 #else
189 B &B::operator=(const B&) = default; // expected-error {{would delete}} expected-note@-9{{inaccessible copy assignment}}
190 B &B::operator=(B&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
191 #endif
194 namespace dr2199 { // dr2199: 3.8
195 // NB: reusing part of dr407 test
196 namespace A {
197 struct S {};
199 namespace B {
200 typedef int S;
202 namespace E {
203 typedef A::S S;
204 using A::S;
205 struct S s;
207 namespace F {
208 typedef A::S S;
210 namespace G {
211 using namespace A;
212 using namespace F;
213 struct S s;
215 namespace H {
216 using namespace F;
217 using namespace A;
218 struct S s;