Debian Codegraph @

clang/test/CXX/drs/cwg25xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx20,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11,since-cxx20,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors
8
9 namespace std {
10 struct type_info{};
11 } // namespace std
12
13 // cwg2504 is in cwg2504.cpp
14
15 namespace cwg2512 { // cwg2512: 2.7
16 struct A; // #cwg2512-A
17 void foo(A* p) {
18 typeid(*p);
19 // expected-error@-1 {{'typeid' of incomplete type 'A'}}
20 // expected-note@#cwg2512-A {{forward declaration of 'cwg2512::A'}}
21 }
22 } // namespace cwg2512
23
24 namespace cwg2516 { // cwg2516: 3.0
25 // NB: reusing 1482 test
26 #if __cplusplus >= 201103L
27 template <typename T> struct S {
28 typedef char I;
29 };
30 enum E2 : S<E2>::I { e };
31 // since-cxx11-error@-1 {{use of undeclared identifier 'E2'}}
32 #endif
33 } // namespace cwg2516
34
35 namespace cwg2518 { // cwg2518: 17
36
37 #if __cplusplus >= 201103L
38 template <class T>
39 void f(T t) {
40 if constexpr (sizeof(T) != sizeof(int)) {
41 // cxx11-14-error@-1 {{constexpr if is a C++17 extension}}
42 static_assert(false, "must be int-sized");
43 // since-cxx11-error@-1 {{static assertion failed: must be int-sized}}
44 // since-cxx11-note@#cwg2518-f-c {{in instantiation of function template specialization 'cwg2518::f<char>' requested here}}
45 }
46 }
47
48 void g(char c) {
49 f(0);
50 f(c); // #cwg2518-f-c
51 }
52
53 template <typename Ty>
54 struct S {
55 static_assert(false);
56 // cxx11-14-error@-1 {{'static_assert' with no message is a C++17 extension}}
57 // since-cxx11-error@-2 {{static assertion failed}}
58 // since-cxx11-note@#cwg2518-S-double {{in instantiation of template class 'cwg2518::S<double>' requested here}}
59 };
60
61 template <>
62 struct S<int> {};
63
64 template <>
65 struct S<float> {};
66
67 int test_specialization() {
68 S<int> s1;
69 S<float> s2;
70 S<double> s3; // #cwg2518-S-double
71 }
72 #endif
73
74 }
75
76 namespace cwg2521 { // cwg2521: 17
77 #if __cplusplus >= 201103L
78 #pragma clang diagnostic push
79 #pragma clang diagnostic warning "-Wdeprecated-literal-operator"
80 long double operator"" _\u03C0___(long double);
81 // since-cxx11-warning@-1 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}
82 // since-cxx11-warning@-2 {{user-defined literal suffixes containing '__' are reserved}}
83
84 template <char... Chars> decltype(sizeof 0)
85 operator"" _div();
86 // since-cxx11-warning@-1 {{identifier '_div' preceded by whitespace in a literal operator declaration is deprecated}}
87
88 using ::cwg2521::operator"" _\u03C0___;
89 using ::cwg2521::operator""_div;
90 // since-cxx11-warning@-2 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}
91 #pragma clang diagnostic pop
92 #endif
93 } // namespace cwg2521
94
95
96 #if __cplusplus >= 202302L
97 namespace cwg2553 { // cwg2553: 18 review 2023-07-14
98 struct B {
99 virtual void f(this B&);
100 // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}
101 static void f(this B&);
102 // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a static function}}
103 virtual void g(); // #cwg2553-g
104 };
105 struct D : B {
106 void g(this D&);
107 // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}
108 // since-cxx23-note@#cwg2553-g {{overridden virtual function is here}}
109 };
110
111 }
112 #endif
113
114 #if __cplusplus >= 202302L
115 namespace cwg2554 { // cwg2554: 18 review 2021-12-10
116 struct B {
117 virtual void f(); // #cwg2554-g
118 };
119
120 struct D : B {
121 void f(this D&);
122 // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}
123 // since-cxx23-note@#cwg2554-g {{overridden virtual function is here}}
124 };
125
126 struct D2 : B {
127 void f(this B&);
128 // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}
129 // since-cxx23-note@#cwg2554-g {{overridden virtual function is here}}
130 };
131 struct T {};
132 struct D3 : B {
133 void f(this T&);
134 // since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}}
135 // since-cxx23-note@#cwg2554-g {{overridden virtual function is here}}
136 };
137
138 }
139 #endif
140
141 #if __cplusplus >= 202302L
142 namespace cwg2561 { // cwg2561: no tentatively ready 2024-03-18
143 struct C {
144 constexpr C(auto) { }
145 };
146 void foo() {
147 constexpr auto b = [](this C) { return 1; };
148 // FIXME: closure type shouldn't have a conversion function to function
149 // pointer, because explicit object parameter is present.
150 constexpr int (*fp)(C) = b;
151 static_assert(fp(1) == 1);
152 static_assert((&decltype(b)::operator())(1) == 1);
153 }
154
155 }
156 #endif
157
158
159 namespace cwg2565 { // cwg2565: 16 open 2023-06-07
160 #if __cplusplus >= 202002L
161 template<typename T>
162 concept C = requires (typename T::type x) {
163 x + 1;
164 };
165 static_assert(!C<int>);
166
167 // Variant of this as reported in GH57487.
168 template<bool B> struct bool_constant
169 { static constexpr bool value = B; };
170
171 template<typename T>
172 using is_referenceable
173 = bool_constant<requires (T&) { true; }>;
174
175 static_assert(!is_referenceable<void>::value);
176 static_assert(is_referenceable<int>::value);
177
178 template<typename T, typename U>
179 concept TwoParams = requires (T *a, U b){ true;}; // #cwg2565-TPC
180
181 template<typename T, typename U>
182 requires TwoParams<T, U> // #cwg2565-TPSREQ
183 struct TwoParamsStruct{};
184
185 using TPSU = TwoParamsStruct<void, void>;
186 // since-cxx20-error@-1 {{constraints not satisfied for class template 'TwoParamsStruct'}}
187 // since-cxx20-note@#cwg2565-TPSREQ {{because 'TwoParams<void, void>' evaluated to false}}
188 // since-cxx20-note@#cwg2565-TPC {{because 'b' would be invalid: argument may not have 'void' type}}
189
190 template<typename T, typename ...U>
191 concept Variadic = requires (U* ... a, T b){ true;}; // #cwg2565-VC
192
193 template<typename T, typename ...U>
194 requires Variadic<T, U...> // #cwg2565-VSREQ
195 struct VariadicStruct{};
196
197 using VSU = VariadicStruct<void, int, char, double>;
198 // since-cxx20-error@-1 {{constraints not satisfied for class template 'VariadicStruct'}}
199 // since-cxx20-note@#cwg2565-VSREQ {{because 'Variadic<void, int, char, double>' evaluated to false}}
200 // since-cxx20-note@#cwg2565-VC {{because 'b' would be invalid: argument may not have 'void' type}}
201
202 template<typename T>
203 concept ErrorRequires = requires (ErrorRequires auto x) {
204 // since-cxx20-error@-1 {{unknown type name 'ErrorRequires'}}
205 x;
206 };
207 static_assert(ErrorRequires<int>);
208 // since-cxx20-error@-1 {{static assertion failed}}
209 // since-cxx20-note@-2 {{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
210
211 template<typename T>
212 concept NestedErrorInRequires = requires (T x) {
213 requires requires (NestedErrorInRequires auto y) {
214 // since-cxx20-error@-1 {{unknown type name 'NestedErrorInRequires'}}
215 y;
216 };
217 };
218 static_assert(NestedErrorInRequires<int>);
219 // expected-error@-1 {{static assertion failed}}
220 // expected-note@-2 {{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
221
222 #endif
223 }
224
225 namespace cwg2583 { // cwg2583: 19
226 #if __cplusplus >= 201103L
227 struct A {
228 int i;
229 char c;
230 };
231
232 struct B {
233 int i;
234 alignas(8) char c;
235 };
236
237 union U {
238 A a;
239 B b;
240 };
241
242 union V {
243 A a;
244 alignas(64) B b;
245 };
246
247 static_assert(!__is_layout_compatible(A, B), "");
248 static_assert(__is_layout_compatible(U, V), "");
249 #endif
250 } // namespace cwg2583
251
252 namespace cwg2598 { // cwg2598: 18
253 #if __cplusplus >= 201103L
254 struct NonLiteral {
255 NonLiteral();
256 };
257
258 struct anonymous1 {
259 union {} a;
260 };
261 static_assert(__is_literal(anonymous1), "");
262
263 struct anonymous2 {
264 union { char c; };
265 };
266 static_assert(__is_literal(anonymous2), "");
267
268 struct anonymous3 {
269 union { char c; NonLiteral NL; };
270 };
271 static_assert(__is_literal(anonymous3), "");
272
273 struct anonymous4 {
274 union { NonLiteral NL; };
275 };
276 static_assert(!__is_literal(anonymous4), "");
277
278 union empty {};
279 static_assert(__is_literal(empty), "");
280
281 union union1 { char c; };
282 static_assert(__is_literal(union1), "");
283
284 union union2 { char c; NonLiteral NL;};
285 static_assert(__is_literal(union2), "");
286
287 union union3 { NonLiteral NL;};
288 static_assert(!__is_literal(union3), "");
289
290 union union4 { union4(); };
291 static_assert(!__is_literal(union4), "");
292
293 union union5 { static NonLiteral NL; };
294 static_assert(__is_literal(union5), "");
295
296 struct Literal { constexpr Literal() {} };
297 union union6 { NonLiteral NL; Literal L; };
298 static_assert(__is_literal(union6), "");
299
300 #if __cplusplus >= 202003L
301 struct A { A(); };
302 union U {
303 A a;
304 constexpr U() {}
305 constexpr ~U() {}
306 };
307 static_assert(!__is_literal(U), "");
308 #endif
309
310
311
312 #endif
313 }