| 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 cwg2517 { // cwg2517: 21 |
| 36 |
#if __cplusplus >= 202002L |
| 37 |
template<typename ArrayType> |
| 38 |
concept LargeArray = requires (ArrayType my_array) { |
| 39 |
requires my_array.size() > 5; |
| 40 |
}; |
| 41 |
|
| 42 |
struct Big { |
| 43 |
constexpr int size() const { return 100; } |
| 44 |
}; |
| 45 |
|
| 46 |
struct Small { |
| 47 |
constexpr int size() const { return 3; } |
| 48 |
}; |
| 49 |
|
| 50 |
static_assert(LargeArray<Big>); |
| 51 |
static_assert(!LargeArray<Small>); |
| 52 |
#endif |
| 53 |
} // namespace cwg2517 |
| 54 |
|
| 55 |
namespace cwg2518 { // cwg2518: 17 |
| 56 |
|
| 57 |
#if __cplusplus >= 201103L |
| 58 |
template <class T> |
| 59 |
void f(T t) { |
| 60 |
if constexpr (sizeof(T) != sizeof(int)) { |
| 61 |
// cxx11-14-error@-1 {{constexpr if is a C++17 extension}} |
| 62 |
static_assert(false, "must be int-sized"); |
| 63 |
// since-cxx11-error@-1 {{static assertion failed: must be int-sized}} |
| 64 |
// since-cxx11-note@#cwg2518-f-c {{in instantiation of function template specialization 'cwg2518::f<char>' requested here}} |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
void g(char c) { |
| 69 |
f(0); |
| 70 |
f(c); // #cwg2518-f-c |
| 71 |
} |
| 72 |
|
| 73 |
template <typename Ty> |
| 74 |
struct S { |
| 75 |
static_assert(false); |
| 76 |
// cxx11-14-error@-1 {{'static_assert' with no message is a C++17 extension}} |
| 77 |
// since-cxx11-error@-2 {{static assertion failed}} |
| 78 |
// since-cxx11-note@#cwg2518-S-double {{in instantiation of template class 'cwg2518::S<double>' requested here}} |
| 79 |
}; |
| 80 |
|
| 81 |
template <> |
| 82 |
struct S<int> {}; |
| 83 |
|
| 84 |
template <> |
| 85 |
struct S<float> {}; |
| 86 |
|
| 87 |
int test_specialization() { |
| 88 |
S<int> s1; |
| 89 |
S<float> s2; |
| 90 |
S<double> s3; // #cwg2518-S-double |
| 91 |
} |
| 92 |
#endif |
| 93 |
|
| 94 |
} // namespace cwg2518 |
| 95 |
|
| 96 |
namespace cwg2521 { // cwg2521: 17 |
| 97 |
#if __cplusplus >= 201103L |
| 98 |
#pragma clang diagnostic push |
| 99 |
#pragma clang diagnostic warning "-Wdeprecated-literal-operator" |
| 100 |
long double operator"" _\u03C0___(long double); |
| 101 |
// since-cxx11-warning@-1 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}} |
| 102 |
// since-cxx11-warning@-2 {{user-defined literal suffixes containing '__' are reserved}} |
| 103 |
|
| 104 |
template <char... Chars> decltype(sizeof 0) |
| 105 |
operator"" _div(); |
| 106 |
// since-cxx11-warning@-1 {{identifier '_div' preceded by whitespace in a literal operator declaration is deprecated}} |
| 107 |
|
| 108 |
using ::cwg2521::operator"" _\u03C0___; |
| 109 |
// since-cxx11-warning@-1 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}} |
| 110 |
using ::cwg2521::operator""_div; |
| 111 |
|
| 112 |
long double operator"" _RESERVED(long double); |
| 113 |
// since-cxx11-warning@-1 {{identifier '_RESERVED' preceded by whitespace in a literal operator declaration is deprecated}} |
| 114 |
#pragma clang diagnostic pop |
| 115 |
#endif |
| 116 |
} // namespace cwg2521 |
| 117 |
|
| 118 |
namespace cwg2547 { // cwg2547: 20 |
| 119 |
#if __cplusplus >= 202302L |
| 120 |
struct S; |
| 121 |
// since-cxx23-note@-1 {{forward declaration of 'cwg2547::S'}} |
| 122 |
// since-cxx23-note@-2 {{forward declaration of 'cwg2547::S'}} |
| 123 |
// since-cxx23-note@-3 {{forward declaration of 'cwg2547::S'}} |
| 124 |
bool operator==(S, S) = default; // error: S is not complete |
| 125 |
// since-cxx23-error@-1 {{variable has incomplete type 'S'}} |
| 126 |
// since-cxx23-error@-2 {{variable has incomplete type 'S'}} |
| 127 |
// since-cxx23-error@-3 {{equality comparison operator is not a friend of incomplete class 'cwg2547::S'}} |
| 128 |
struct S { |
| 129 |
friend bool operator==(S, const S&) = default; // error: parameters of different types |
| 130 |
// since-cxx23-error@-1 {{parameters for defaulted equality comparison operator must have the same type (found 'S' vs 'const S &')}} |
| 131 |
}; |
| 132 |
enum E { }; |
| 133 |
bool operator==(E, E) = default; // error: not a member or friend of a class |
| 134 |
// since-cxx23-error@-1 {{invalid parameter type for non-member defaulted equality comparison operator; found 'E', expected class or reference to a constant class}} |
| 135 |
|
| 136 |
struct S2 { |
| 137 |
bool operator==(this int, S2) = default; |
| 138 |
// since-cxx23-error@-1 {{invalid parameter type for defaulted equality comparison operator; found 'int', expected 'const cwg2547::S2 &'}} |
| 139 |
}; |
| 140 |
#endif |
| 141 |
} // namespace cwg2547 |
| 142 |
|
| 143 |
namespace cwg2553 { // cwg2553: 18 review 2023-07-14 |
| 144 |
#if __cplusplus >= 202302L |
| 145 |
struct B { |
| 146 |
virtual void f(this B&); |
| 147 |
// since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}} |
| 148 |
static void f(this B&); |
| 149 |
// since-cxx23-error@-1 {{an explicit object parameter cannot appear in a static function}} |
| 150 |
virtual void g(); // #cwg2553-g |
| 151 |
}; |
| 152 |
struct D : B { |
| 153 |
void g(this D&); |
| 154 |
// since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}} |
| 155 |
// since-cxx23-note@#cwg2553-g {{overridden virtual function is here}} |
| 156 |
}; |
| 157 |
#endif |
| 158 |
} // namespace cwg2553 |
| 159 |
|
| 160 |
namespace cwg2554 { // cwg2554: 18 review 2021-12-10 |
| 161 |
#if __cplusplus >= 202302L |
| 162 |
struct B { |
| 163 |
virtual void f(); // #cwg2554-g |
| 164 |
}; |
| 165 |
|
| 166 |
struct D : B { |
| 167 |
void f(this D&); |
| 168 |
// since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}} |
| 169 |
// since-cxx23-note@#cwg2554-g {{overridden virtual function is here}} |
| 170 |
}; |
| 171 |
|
| 172 |
struct D2 : B { |
| 173 |
void f(this B&); |
| 174 |
// since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}} |
| 175 |
// since-cxx23-note@#cwg2554-g {{overridden virtual function is here}} |
| 176 |
}; |
| 177 |
struct T {}; |
| 178 |
struct D3 : B { |
| 179 |
void f(this T&); |
| 180 |
// since-cxx23-error@-1 {{an explicit object parameter cannot appear in a virtual function}} |
| 181 |
// since-cxx23-note@#cwg2554-g {{overridden virtual function is here}} |
| 182 |
}; |
| 183 |
#endif |
| 184 |
} // namespace cwg2554 |
| 185 |
|
| 186 |
namespace cwg2561 { // cwg2561: no |
| 187 |
#if __cplusplus >= 202302L |
| 188 |
struct C { |
| 189 |
constexpr C(auto) { } |
| 190 |
}; |
| 191 |
void foo() { |
| 192 |
constexpr auto b = [](this C) { return 1; }; |
| 193 |
// FIXME: closure type shouldn't have a conversion function to function |
| 194 |
// pointer, because explicit object parameter is present. |
| 195 |
constexpr int (*fp)(C) = b; |
| 196 |
static_assert(fp(1) == 1); |
| 197 |
static_assert((&decltype(b)::operator())(1) == 1); |
| 198 |
} |
| 199 |
#endif |
| 200 |
} // namespace cwg2561 |
| 201 |
|
| 202 |
namespace cwg2565 { // cwg2565: 16 open 2023-06-07 |
| 203 |
#if __cplusplus >= 202002L |
| 204 |
template<typename T> |
| 205 |
concept C = requires (typename T::type x) { |
| 206 |
x + 1; |
| 207 |
}; |
| 208 |
static_assert(!C<int>); |
| 209 |
|
| 210 |
// Variant of this as reported in GH57487. |
| 211 |
template<bool B> struct bool_constant |
| 212 |
{ static constexpr bool value = B; }; |
| 213 |
|
| 214 |
template<typename T> |
| 215 |
using is_referenceable |
| 216 |
= bool_constant<requires (T&) { true; }>; |
| 217 |
|
| 218 |
static_assert(!is_referenceable<void>::value); |
| 219 |
static_assert(is_referenceable<int>::value); |
| 220 |
|
| 221 |
template<typename T, typename U> |
| 222 |
concept TwoParams = requires (T *a, U b){ true;}; // #cwg2565-TPC |
| 223 |
|
| 224 |
template<typename T, typename U> |
| 225 |
requires TwoParams<T, U> // #cwg2565-TPSREQ |
| 226 |
struct TwoParamsStruct{}; |
| 227 |
|
| 228 |
using TPSU = TwoParamsStruct<void, void>; |
| 229 |
// since-cxx20-error@-1 {{constraints not satisfied for class template 'TwoParamsStruct' [with T = void, U = void]}} |
| 230 |
// since-cxx20-note@#cwg2565-TPSREQ {{because 'TwoParams<void, void>' evaluated to false}} |
| 231 |
// since-cxx20-note@#cwg2565-TPC {{because 'b' would be invalid: argument may not have 'void' type}} |
| 232 |
|
| 233 |
template<typename T, typename ...U> |
| 234 |
concept Variadic = requires (U* ... a, T b){ true;}; // #cwg2565-VC |
| 235 |
|
| 236 |
template<typename T, typename ...U> |
| 237 |
requires Variadic<T, U...> // #cwg2565-VSREQ |
| 238 |
struct VariadicStruct{}; |
| 239 |
|
| 240 |
using VSU = VariadicStruct<void, int, char, double>; |
| 241 |
// since-cxx20-error@-1 {{constraints not satisfied for class template 'VariadicStruct' [with T = void, U = <int, char, double>]}} |
| 242 |
// since-cxx20-note@#cwg2565-VSREQ {{because 'Variadic<void, int, char, double>' evaluated to false}} |
| 243 |
// since-cxx20-note@#cwg2565-VC {{because 'b' would be invalid: argument may not have 'void' type}} |
| 244 |
|
| 245 |
template<typename T> |
| 246 |
concept ErrorRequires = requires (ErrorRequires auto x) { // #cwg2565-expr |
| 247 |
// since-cxx20-error@-1 {{a concept definition cannot refer to itself}} |
| 248 |
// since-cxx20-note@-2 {{declared here}} |
| 249 |
// since-cxx20-error@-3 {{'auto' not allowed in requires expression parameter}} |
| 250 |
x; |
| 251 |
}; |
| 252 |
static_assert(ErrorRequires<int>); |
| 253 |
// since-cxx20-error@-1 {{static assertion failed}} \ |
| 254 |
// since-cxx20-note@-1 {{because 'int' does not satisfy 'ErrorRequires'}} \ |
| 255 |
// since-cxx20-note@#cwg2565-expr {{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}} |
| 256 |
|
| 257 |
template<typename T> |
| 258 |
concept NestedErrorInRequires = requires (T x) { // #cwg2565-NEIR |
| 259 |
requires requires (NestedErrorInRequires auto y) { // #cwg2565-NEIR-inner |
| 260 |
// since-cxx20-error@-1 {{a concept definition cannot refer to itself}} |
| 261 |
// since-cxx20-note@#cwg2565-NEIR {{declared here}} |
| 262 |
// since-cxx20-error@-3 {{'auto' not allowed in requires expression parameter}} |
| 263 |
y; |
| 264 |
}; |
| 265 |
}; |
| 266 |
static_assert(NestedErrorInRequires<int>); |
| 267 |
// since-cxx20-error@-1 {{static assertion failed}} \ |
| 268 |
// since-cxx20-note@-1 {{because 'int' does not satisfy 'NestedErrorInRequires'}} \ |
| 269 |
// since-cxx20-note-re@#cwg2565-NEIR-inner {{because {{.*}} would be invalid: constraint depends on a previously diagnosed expression}} |
| 270 |
|
| 271 |
#endif |
| 272 |
} // namespace cwg2565 |
| 273 |
|
| 274 |
namespace cwg2583 { // cwg2583: 19 |
| 275 |
#if __cplusplus >= 201103L |
| 276 |
struct A { |
| 277 |
int i; |
| 278 |
char c; |
| 279 |
}; |
| 280 |
|
| 281 |
struct B { |
| 282 |
int i; |
| 283 |
alignas(8) char c; |
| 284 |
}; |
| 285 |
|
| 286 |
union U { |
| 287 |
A a; |
| 288 |
B b; |
| 289 |
}; |
| 290 |
|
| 291 |
union V { |
| 292 |
A a; |
| 293 |
alignas(64) B b; |
| 294 |
}; |
| 295 |
|
| 296 |
static_assert(!__is_layout_compatible(A, B), ""); |
| 297 |
static_assert(__is_layout_compatible(U, V), ""); |
| 298 |
#endif |
| 299 |
} // namespace cwg2583 |
| 300 |
|
| 301 |
namespace cwg2586 { // cwg2586: 20 |
| 302 |
#if __cplusplus >= 202302L |
| 303 |
struct X { |
| 304 |
X& operator=(this X&, const X&) = default; |
| 305 |
X& operator=(this X&, X&) = default; |
| 306 |
X& operator=(this X&&, X&&) = default; |
| 307 |
// FIXME: The notes could be clearer on *how* the type differs |
| 308 |
// e.g., "if an explicit object parameter is used it must be of type reference to 'X'" |
| 309 |
X& operator=(this int, const X&) = default; |
| 310 |
// since-cxx23-warning@-1 {{explicitly defaulted copy assignment operator is implicitly deleted}} |
| 311 |
// since-cxx23-note@-2 {{function is implicitly deleted because its declared type does not match the type of an implicit copy assignment operator}} |
| 312 |
X& operator=(this X, const X&) = default; |
| 313 |
// since-cxx23-warning@-1 {{explicitly defaulted copy assignment operator is implicitly deleted}} |
| 314 |
// since-cxx23-note@-2 {{function is implicitly deleted because its declared type does not match the type of an implicit copy assignment operator}} |
| 315 |
}; |
| 316 |
struct Y { |
| 317 |
void operator=(this int, const Y&); // This is copy constructor, suppresses implicit declaration |
| 318 |
}; |
| 319 |
static_assert([]<typename T = Y>{ |
| 320 |
return !requires(T t, const T& ct) { t = ct; }; |
| 321 |
}()); |
| 322 |
|
| 323 |
struct Z { |
| 324 |
bool operator==(this const Z&, const Z&) = default; |
| 325 |
bool operator==(this Z, Z) = default; |
| 326 |
bool operator==(this Z, const Z&) = default; |
| 327 |
// since-cxx23-error@-1 {{parameters for defaulted equality comparison operator must have the same type (found 'Z' vs 'const Z &')}} |
| 328 |
bool operator==(this const Z&, Z) = default; |
| 329 |
// since-cxx23-error@-1 {{parameters for defaulted equality comparison operator must have the same type (found 'const Z &' vs 'Z')}} |
| 330 |
bool operator==(this int, Z) = default; |
| 331 |
// since-cxx23-error@-1 {{invalid parameter type for defaulted equality comparison operator; found 'int', expected 'const cwg2586::Z &'}} |
| 332 |
}; |
| 333 |
#endif |
| 334 |
} // namespace cwg2586 |
| 335 |
|
| 336 |
namespace cwg2598 { // cwg2598: 18 |
| 337 |
#if __cplusplus >= 201103L |
| 338 |
struct NonLiteral { |
| 339 |
NonLiteral(); |
| 340 |
}; |
| 341 |
|
| 342 |
struct anonymous1 { |
| 343 |
union {} a; |
| 344 |
}; |
| 345 |
static_assert(__is_literal(anonymous1), ""); |
| 346 |
|
| 347 |
struct anonymous2 { |
| 348 |
union { char c; }; |
| 349 |
}; |
| 350 |
static_assert(__is_literal(anonymous2), ""); |
| 351 |
|
| 352 |
struct anonymous3 { |
| 353 |
union { char c; NonLiteral NL; }; |
| 354 |
}; |
| 355 |
static_assert(__is_literal(anonymous3), ""); |
| 356 |
|
| 357 |
struct anonymous4 { |
| 358 |
union { NonLiteral NL; }; |
| 359 |
}; |
| 360 |
static_assert(!__is_literal(anonymous4), ""); |
| 361 |
|
| 362 |
union empty {}; |
| 363 |
static_assert(__is_literal(empty), ""); |
| 364 |
|
| 365 |
union union1 { char c; }; |
| 366 |
static_assert(__is_literal(union1), ""); |
| 367 |
|
| 368 |
union union2 { char c; NonLiteral NL;}; |
| 369 |
static_assert(__is_literal(union2), ""); |
| 370 |
|
| 371 |
union union3 { NonLiteral NL;}; |
| 372 |
static_assert(!__is_literal(union3), ""); |
| 373 |
|
| 374 |
union union4 { union4(); }; |
| 375 |
static_assert(!__is_literal(union4), ""); |
| 376 |
|
| 377 |
union union5 { static NonLiteral NL; }; |
| 378 |
static_assert(__is_literal(union5), ""); |
| 379 |
|
| 380 |
struct Literal { constexpr Literal() {} }; |
| 381 |
union union6 { NonLiteral NL; Literal L; }; |
| 382 |
static_assert(__is_literal(union6), ""); |
| 383 |
|
| 384 |
#if __cplusplus >= 202003L |
| 385 |
struct A { A(); }; |
| 386 |
union U { |
| 387 |
A a; |
| 388 |
constexpr U() {} |
| 389 |
constexpr ~U() {} |
| 390 |
}; |
| 391 |
static_assert(!__is_literal(U), ""); |
| 392 |
#endif |
| 393 |
#endif |
| 394 |
} // namespace cwg2598 |