| 1 |
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,cxx98 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors |
| 2 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,cxx11-17,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors |
| 3 |
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,cxx98-14,cxx11-17,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors |
| 4 |
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx17,cxx11-17,since-cxx11,since-cxx14,cxx17 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors |
| 5 |
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors |
| 6 |
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors |
| 7 |
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx14,since-cxx17,since-cxx20,since-cxx11,since-cxx14 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors |
| 8 |
|
| 9 |
#if __cplusplus == 199711L |
| 10 |
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__) |
| 11 |
// cxx98-error@-1 {{variadic macros are a C99 feature}} |
| 12 |
#endif |
| 13 |
|
| 14 |
namespace cwg1800 { // cwg1800: 2.9 |
| 15 |
struct A { union { int n; }; }; |
| 16 |
static_assert(__is_same(__decltype(&A::n), int A::*), ""); |
| 17 |
} // namespace cwg1800 |
| 18 |
|
| 19 |
namespace cwg1801 { // cwg1801: 2.8 |
| 20 |
static union { |
| 21 |
int i; |
| 22 |
}; |
| 23 |
|
| 24 |
template <int &> struct S {}; // #cwg1801-S |
| 25 |
S<i> V; // #cwg1801-S-i |
| 26 |
// cxx98-14-error@-1 {{non-type template argument does not refer to any declaration}} |
| 27 |
// cxx98-14-note@#cwg1801-S {{template parameter is declared here}} |
| 28 |
// cxx17-error@#cwg1801-S-i {{non-type template argument refers to subobject '.i'}} |
| 29 |
} |
| 30 |
|
| 31 |
namespace cwg1802 { // cwg1802: 3.1 |
| 32 |
#if __cplusplus >= 201103L |
| 33 |
// Using a Wikipedia example of surrogate pair: |
| 34 |
// https://en.wikipedia.org/wiki/UTF-16#Examples |
| 35 |
constexpr char16_t a[3] = u"\U00010437"; |
| 36 |
static_assert(a[0] == 0xD801, ""); |
| 37 |
static_assert(a[1] == 0xDC37, ""); |
| 38 |
static_assert(a[2] == 0x0, ""); |
| 39 |
#endif |
| 40 |
} // namespace cwg1802 |
| 41 |
|
| 42 |
namespace cwg1803 { // cwg1803: 2.9 |
| 43 |
#if __cplusplus >= 201103L |
| 44 |
struct A { |
| 45 |
enum E : int; |
| 46 |
enum E : int {}; |
| 47 |
enum class EC; |
| 48 |
enum class EC {}; |
| 49 |
enum struct ES; |
| 50 |
enum struct ES {}; |
| 51 |
}; |
| 52 |
#endif |
| 53 |
} // namespace cwg1803 |
| 54 |
|
| 55 |
namespace cwg1804 { // cwg1804: 2.7 |
| 56 |
template <typename, typename> |
| 57 |
struct A { |
| 58 |
void f1(); |
| 59 |
|
| 60 |
template <typename V> |
| 61 |
void f2(V); |
| 62 |
|
| 63 |
class B { |
| 64 |
void f3(); |
| 65 |
}; |
| 66 |
|
| 67 |
template <typename> |
| 68 |
class C { |
| 69 |
void f4(); |
| 70 |
}; |
| 71 |
}; |
| 72 |
|
| 73 |
template <typename U> |
| 74 |
struct A<int, U> { |
| 75 |
void f1(); |
| 76 |
|
| 77 |
template <typename V> |
| 78 |
void f2(V); |
| 79 |
|
| 80 |
class B { |
| 81 |
void f3(); |
| 82 |
}; |
| 83 |
|
| 84 |
template <typename> |
| 85 |
class C { |
| 86 |
void f4(); |
| 87 |
}; |
| 88 |
}; |
| 89 |
|
| 90 |
class D { |
| 91 |
int i; |
| 92 |
|
| 93 |
template <typename, typename> |
| 94 |
friend struct A; |
| 95 |
}; |
| 96 |
|
| 97 |
template <typename U> |
| 98 |
struct A<double, U> { |
| 99 |
void f1(); |
| 100 |
|
| 101 |
template <typename V> |
| 102 |
void f2(V); |
| 103 |
|
| 104 |
class B { |
| 105 |
void f3(); |
| 106 |
}; |
| 107 |
|
| 108 |
template <typename> |
| 109 |
class C { |
| 110 |
void f4(); |
| 111 |
}; |
| 112 |
}; |
| 113 |
|
| 114 |
template <typename U> |
| 115 |
void A<int, U>::f1() { |
| 116 |
D d; |
| 117 |
d.i = 0; |
| 118 |
} |
| 119 |
|
| 120 |
template <typename U> |
| 121 |
void A<double, U>::f1() { |
| 122 |
D d; |
| 123 |
d.i = 0; |
| 124 |
} |
| 125 |
|
| 126 |
template <typename U> |
| 127 |
template <typename V> |
| 128 |
void A<int, U>::f2(V) { |
| 129 |
D d; |
| 130 |
d.i = 0; |
| 131 |
} |
| 132 |
|
| 133 |
template <typename U> |
| 134 |
template <typename V> |
| 135 |
void A<double, U>::f2(V) { |
| 136 |
D d; |
| 137 |
d.i = 0; |
| 138 |
} |
| 139 |
|
| 140 |
template <typename U> |
| 141 |
void A<int, U>::B::f3() { |
| 142 |
D d; |
| 143 |
d.i = 0; |
| 144 |
} |
| 145 |
|
| 146 |
template <typename U> |
| 147 |
void A<double, U>::B::f3() { |
| 148 |
D d; |
| 149 |
d.i = 0; |
| 150 |
} |
| 151 |
|
| 152 |
template <typename U> |
| 153 |
template <typename V> |
| 154 |
void A<int, U>::C<V>::f4() { |
| 155 |
D d; |
| 156 |
d.i = 0; |
| 157 |
} |
| 158 |
|
| 159 |
template <typename U> |
| 160 |
template <typename V> |
| 161 |
void A<double, U>::C<V>::f4() { |
| 162 |
D d; |
| 163 |
d.i = 0; |
| 164 |
} |
| 165 |
} // namespace cwg1804 |
| 166 |
|
| 167 |
// cwg1807 is in cwg1807.cpp |
| 168 |
|
| 169 |
namespace cwg1812 { // cwg1812: no |
| 170 |
// NB: dup 1710 |
| 171 |
#if __cplusplus >= 201103L |
| 172 |
template <typename T> struct A { |
| 173 |
using B = typename T::C<int>; |
| 174 |
// since-cxx11-error@-1 {{use 'template' keyword to treat 'C' as a dependent template name}} |
| 175 |
}; |
| 176 |
#endif |
| 177 |
} // namespace cwg1812 |
| 178 |
|
| 179 |
namespace cwg1813 { // cwg1813: 7 |
| 180 |
struct B { int i; }; |
| 181 |
struct C : B {}; |
| 182 |
struct D : C {}; |
| 183 |
struct E : D { char : 4; }; |
| 184 |
|
| 185 |
static_assert(__is_standard_layout(B), ""); |
| 186 |
static_assert(__is_standard_layout(C), ""); |
| 187 |
static_assert(__is_standard_layout(D), ""); |
| 188 |
static_assert(!__is_standard_layout(E), ""); |
| 189 |
|
| 190 |
struct Q {}; |
| 191 |
struct S : Q {}; |
| 192 |
struct T : Q {}; |
| 193 |
struct U : S, T {}; |
| 194 |
|
| 195 |
static_assert(__is_standard_layout(Q), ""); |
| 196 |
static_assert(__is_standard_layout(S), ""); |
| 197 |
static_assert(__is_standard_layout(T), ""); |
| 198 |
static_assert(!__is_standard_layout(U), ""); |
| 199 |
} |
| 200 |
|
| 201 |
namespace cwg1814 { // cwg1814: yes |
| 202 |
#if __cplusplus >= 201103L |
| 203 |
void test() { |
| 204 |
auto lam = [](int x = 42) { return x; }; |
| 205 |
} |
| 206 |
#endif |
| 207 |
} |
| 208 |
|
| 209 |
namespace cwg1815 { // cwg1815: no |
| 210 |
#if __cplusplus >= 201402L |
| 211 |
// FIXME: needs codegen test |
| 212 |
struct A { int &&r = 0; }; // #cwg1815-A |
| 213 |
A a = {}; |
| 214 |
// since-cxx14-warning@-1 {{lifetime extension of temporary created by aggregate initialization using a default member initializer is not yet supported; lifetime of temporary will end at the end of the full-expression}} FIXME |
| 215 |
// since-cxx14-note@#cwg1815-A {{initializing field 'r' with default member initializer}} |
| 216 |
|
| 217 |
struct B { int &&r = 0; }; // #cwg1815-B |
| 218 |
// since-cxx14-error@-1 {{reference member 'r' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}} |
| 219 |
// since-cxx14-note@#cwg1815-B {{initializing field 'r' with default member initializer}} |
| 220 |
// since-cxx14-note@#cwg1815-b {{in implicit default constructor for 'cwg1815::B' first required here}} |
| 221 |
B b; // #cwg1815-b |
| 222 |
#endif |
| 223 |
} |
| 224 |
|
| 225 |
namespace cwg1820 { // cwg1820: 3.5 |
| 226 |
typedef int A; |
| 227 |
typedef int cwg1820::A; |
| 228 |
// expected-warning@-1 {{extra qualification on member 'A'}} |
| 229 |
// expected-error@-2 {{typedef declarator cannot be qualified}} |
| 230 |
|
| 231 |
namespace B { |
| 232 |
typedef int cwg1820::A; |
| 233 |
// expected-error@-1 {{cannot define or redeclare 'A' here because namespace 'B' does not enclose namespace 'cwg1820'}} |
| 234 |
// expected-error@-2 {{typedef declarator cannot be qualified}} |
| 235 |
} |
| 236 |
|
| 237 |
class C1 { |
| 238 |
typedef int cwg1820::A; |
| 239 |
// expected-error@-1 {{non-friend class member 'A' cannot have a qualified name}} |
| 240 |
// expected-error@-2 {{typedef declarator cannot be qualified}} |
| 241 |
}; |
| 242 |
|
| 243 |
template <typename> |
| 244 |
class C2 { |
| 245 |
typedef int cwg1820::A; |
| 246 |
// expected-error@-1 {{non-friend class member 'A' cannot have a qualified name}} |
| 247 |
// expected-error@-2 {{typedef declarator cannot be qualified}} |
| 248 |
}; |
| 249 |
|
| 250 |
void d1() { |
| 251 |
typedef int cwg1820::A; |
| 252 |
// expected-error@-1 {{definition or redeclaration of 'A' not allowed inside a function}} |
| 253 |
// expected-error@-2 {{typedef declarator cannot be qualified}} |
| 254 |
} |
| 255 |
|
| 256 |
template<typename> |
| 257 |
void d2() { |
| 258 |
typedef int cwg1820::A; |
| 259 |
// expected-error@-1 {{definition or redeclaration of 'A' not allowed inside a function}} |
| 260 |
// expected-error@-2 {{typedef declarator cannot be qualified}} |
| 261 |
} |
| 262 |
|
| 263 |
#if __cplusplus >= 201103L |
| 264 |
auto e = [] { |
| 265 |
typedef int cwg1820::A; |
| 266 |
// expected-error@-1 {{definition or redeclaration of 'A' not allowed inside a function}} |
| 267 |
// expected-error@-2 {{typedef declarator cannot be qualified}} |
| 268 |
}; |
| 269 |
#endif |
| 270 |
} // namespace cwg1820 |
| 271 |
|
| 272 |
namespace cwg1821 { // cwg1821: 2.9 |
| 273 |
struct A { |
| 274 |
template <typename> struct B { |
| 275 |
void f(); |
| 276 |
}; |
| 277 |
template <typename T> void B<T>::f(){}; |
| 278 |
// expected-error@-1 {{non-friend class member 'f' cannot have a qualified name}} |
| 279 |
|
| 280 |
struct C { |
| 281 |
void f(); |
| 282 |
}; |
| 283 |
void C::f() {} |
| 284 |
// expected-error@-1 {{non-friend class member 'f' cannot have a qualified name}} |
| 285 |
}; |
| 286 |
} // namespace cwg1821 |
| 287 |
|
| 288 |
namespace cwg1822 { // cwg1822: yes |
| 289 |
#if __cplusplus >= 201103L |
| 290 |
double a; |
| 291 |
auto x = [] (int a) { |
| 292 |
static_assert(__is_same(decltype(a), int), "should be resolved to lambda parameter"); |
| 293 |
}; |
| 294 |
#endif |
| 295 |
} |
| 296 |
|
| 297 |
namespace cwg1824 { // cwg1824: 2.7 |
| 298 |
template<typename T> |
| 299 |
struct A { |
| 300 |
T t; |
| 301 |
}; |
| 302 |
|
| 303 |
struct S { |
| 304 |
A<S> f() { return A<S>(); } |
| 305 |
}; |
| 306 |
} // namespace cwg1824 |
| 307 |
|
| 308 |
namespace cwg1832 { // cwg1832: 3.0 |
| 309 |
enum E { // #cwg1832-E |
| 310 |
a = static_cast<int>(static_cast<E>(0)) |
| 311 |
// expected-error@-1 {{'E' is an incomplete type}} |
| 312 |
// expected-note@#cwg1832-E {{definition of 'cwg1832::E' is not complete until the closing '}'}} |
| 313 |
}; |
| 314 |
|
| 315 |
#if __cplusplus >= 201103L |
| 316 |
enum E2: decltype(static_cast<E2>(0), 0) {}; |
| 317 |
// expected-error@-1 {{unknown type name 'E2'}} |
| 318 |
enum class E3: decltype(static_cast<E3>(0), 0) {}; |
| 319 |
// expected-error@-1 {{unknown type name 'E3'}} |
| 320 |
#endif |
| 321 |
} // namespace cwg1832 |
| 322 |
|
| 323 |
namespace cwg1837 { // cwg1837: 3.3 |
| 324 |
#if __cplusplus >= 201103L |
| 325 |
template <typename T> |
| 326 |
struct Fish { static const bool value = true; }; |
| 327 |
|
| 328 |
struct Other { |
| 329 |
int p(); |
| 330 |
auto q() -> decltype(p()) *; |
| 331 |
}; |
| 332 |
|
| 333 |
class Outer { |
| 334 |
friend auto Other::q() -> decltype(this->p()) *; |
| 335 |
// since-cxx11-error@-1 {{invalid use of 'this' outside of a non-static member function}} |
| 336 |
int g(); |
| 337 |
int f() { |
| 338 |
extern void f(decltype(this->g()) *); |
| 339 |
struct Inner { |
| 340 |
static_assert(Fish<decltype(this->g())>::value, ""); |
| 341 |
// since-cxx11-error@-1 {{invalid use of 'this' outside of a non-static member function}} |
| 342 |
enum { X = Fish<decltype(this->f())>::value }; |
| 343 |
// since-cxx11-error@-1 {{invalid use of 'this' outside of a non-static member function}} |
| 344 |
struct Inner2 : Fish<decltype(this->g())> { }; |
| 345 |
// since-cxx11-error@-1 {{invalid use of 'this' outside of a non-static member function}} |
| 346 |
friend void f(decltype(this->g()) *); |
| 347 |
// since-cxx11-error@-1 {{invalid use of 'this' outside of a non-static member function}} |
| 348 |
friend auto Other::q() -> decltype(this->p()) *; |
| 349 |
// since-cxx11-error@-1 {{invalid use of 'this' outside of a non-static member function}} |
| 350 |
}; |
| 351 |
return 0; |
| 352 |
} |
| 353 |
}; |
| 354 |
|
| 355 |
struct A { |
| 356 |
int f(); |
| 357 |
bool b = [] { |
| 358 |
// since-cxx11-warning@-1 {{address of lambda function pointer conversion operator will always evaluate to 'true'}} |
| 359 |
struct Local { |
| 360 |
static_assert(sizeof(this->f()) == sizeof(int), ""); |
| 361 |
}; |
| 362 |
}; |
| 363 |
}; |
| 364 |
#endif |
| 365 |
} |
| 366 |
|
| 367 |
namespace cwg1862 { // cwg1862: no |
| 368 |
template<class T> |
| 369 |
struct A { |
| 370 |
struct B { |
| 371 |
void e(); |
| 372 |
}; |
| 373 |
|
| 374 |
void f(); |
| 375 |
|
| 376 |
struct D { |
| 377 |
void g(); |
| 378 |
}; |
| 379 |
|
| 380 |
T h(); |
| 381 |
|
| 382 |
template<T U> |
| 383 |
T i(); |
| 384 |
}; |
| 385 |
|
| 386 |
template<> |
| 387 |
struct A<int> { |
| 388 |
struct B { |
| 389 |
void e(); |
| 390 |
}; |
| 391 |
|
| 392 |
int f(); |
| 393 |
|
| 394 |
struct D { |
| 395 |
void g(); |
| 396 |
}; |
| 397 |
|
| 398 |
template<int U> |
| 399 |
int i(); |
| 400 |
}; |
| 401 |
|
| 402 |
template<> |
| 403 |
struct A<float*> { |
| 404 |
int* h(); |
| 405 |
}; |
| 406 |
|
| 407 |
class C { |
| 408 |
int private_int; |
| 409 |
|
| 410 |
template<class T> |
| 411 |
friend struct A<T>::B; |
| 412 |
// expected-warning@-1 {{dependent nested name specifier 'A<T>::' for friend class declaration is not supported; turning off access control for 'C'}} |
| 413 |
|
| 414 |
template<class T> |
| 415 |
friend void A<T>::f(); |
| 416 |
// expected-warning@-1 {{dependent nested name specifier 'A<T>::' for friend class declaration is not supported; turning off access control for 'C'}} |
| 417 |
|
| 418 |
// FIXME: this is ill-formed, because A<T>::D does not end with a simple-template-id |
| 419 |
template<class T> |
| 420 |
friend void A<T>::D::g(); |
| 421 |
// expected-warning@-1 {{dependent nested name specifier 'A<T>::D::' for friend class declaration is not supported; turning off access control for 'C'}} |
| 422 |
|
| 423 |
template<class T> |
| 424 |
friend int *A<T*>::h(); |
| 425 |
// expected-warning@-1 {{dependent nested name specifier 'A<T *>::' for friend class declaration is not supported; turning off access control for 'C'}} |
| 426 |
|
| 427 |
template<class T> |
| 428 |
template<T U> |
| 429 |
friend T A<T>::i(); |
| 430 |
// expected-warning@-1 {{dependent nested name specifier 'A<T>::' for friend class declaration is not supported; turning off access control for 'C'}} |
| 431 |
}; |
| 432 |
|
| 433 |
C c; |
| 434 |
|
| 435 |
template<class T> |
| 436 |
void A<T>::B::e() { (void)c.private_int; } |
| 437 |
void A<int>::B::e() { (void)c.private_int; } |
| 438 |
|
| 439 |
template<class T> |
| 440 |
void A<T>::f() { (void)c.private_int; } |
| 441 |
int A<int>::f() { (void)c.private_int; return 0; } |
| 442 |
|
| 443 |
// FIXME: both definition of 'D::g' are not friends, so they don't have access to 'private_int' |
| 444 |
template<class T> |
| 445 |
void A<T>::D::g() { (void)c.private_int; } |
| 446 |
void A<int>::D::g() { (void)c.private_int; } |
| 447 |
|
| 448 |
template<class T> |
| 449 |
T A<T>::h() { (void)c.private_int; } |
| 450 |
int* A<float*>::h() { (void)c.private_int; return 0; } |
| 451 |
|
| 452 |
template<class T> |
| 453 |
template<T U> |
| 454 |
T A<T>::i() { (void)c.private_int; } |
| 455 |
template<int U> |
| 456 |
int A<int>::i() { (void)c.private_int; } |
| 457 |
} // namespace cwg1862 |
| 458 |
|
| 459 |
namespace cwg1872 { // cwg1872: 9 |
| 460 |
#if __cplusplus >= 201103L |
| 461 |
template<typename T> struct A : T { |
| 462 |
constexpr int f() const { return 0; } |
| 463 |
}; |
| 464 |
struct X {}; |
| 465 |
struct Y { virtual int f() const; }; |
| 466 |
struct Z : virtual X {}; |
| 467 |
|
| 468 |
constexpr int x = A<X>().f(); |
| 469 |
constexpr int y = A<Y>().f(); |
| 470 |
// cxx11-17-error@-1 {{constexpr variable 'y' must be initialized by a constant expression}} |
| 471 |
// cxx11-17-note@-2 {{cannot evaluate call to virtual function in a constant expression in C++ standards before C++20}} |
| 472 |
#if __cplusplus >= 202002L |
| 473 |
static_assert(y == 0); |
| 474 |
#endif |
| 475 |
// Note, this is invalid even though it would not use virtual dispatch. |
| 476 |
constexpr int y2 = A<Y>().A<Y>::f(); |
| 477 |
// cxx11-17-error@-1 {{constexpr variable 'y2' must be initialized by a constant expression}} |
| 478 |
// cxx11-17-note@-2 {{cannot evaluate call to virtual function in a constant expression in C++ standards before C++20}} |
| 479 |
#if __cplusplus >= 202002L |
| 480 |
static_assert(y == 0); |
| 481 |
#endif |
| 482 |
constexpr int z = A<Z>().f(); |
| 483 |
// since-cxx11-error@-1 {{constexpr variable 'z' must be initialized by a constant expression}} |
| 484 |
// since-cxx11-note@-2 {{non-literal type 'A<Z>' cannot be used in a constant expression}} |
| 485 |
#endif |
| 486 |
} |
| 487 |
|
| 488 |
namespace cwg1878 { // cwg1878: 18 |
| 489 |
#if __cplusplus >= 201402L |
| 490 |
#if __cplusplus >= 202002L |
| 491 |
template <typename T> |
| 492 |
concept C = true; |
| 493 |
#endif |
| 494 |
|
| 495 |
struct S { |
| 496 |
template <typename T> |
| 497 |
operator auto() const { return short(); } |
| 498 |
// since-cxx14-error@-1 {{'auto' not allowed in declaration of conversion function template}} |
| 499 |
template <typename T> |
| 500 |
operator const auto() const { return int(); } |
| 501 |
// since-cxx14-error@-1 {{'auto' not allowed in declaration of conversion function template}} |
| 502 |
template <typename T> |
| 503 |
operator const auto&() const { return char(); } |
| 504 |
// since-cxx14-error@-1 {{'auto' not allowed in declaration of conversion function template}} |
| 505 |
template <typename T> |
| 506 |
operator const auto*() const { return long(); } |
| 507 |
// since-cxx14-error@-1 {{'auto' not allowed in declaration of conversion function template}} |
| 508 |
template <typename T> |
| 509 |
operator decltype(auto)() const { return unsigned(); } |
| 510 |
// since-cxx14-error@-1 {{'decltype(auto)' not allowed in declaration of conversion function template}} |
| 511 |
#if __cplusplus >= 202002L |
| 512 |
template <typename T> |
| 513 |
operator C auto() const { return float(); } |
| 514 |
// since-cxx20-error@-1 {{'auto' not allowed in declaration of conversion function template}} |
| 515 |
template <typename T> |
| 516 |
operator C decltype(auto)() const { return double(); } |
| 517 |
// since-cxx20-error@-1 {{'decltype(auto)' not allowed in declaration of conversion function template}} |
| 518 |
#endif |
| 519 |
}; |
| 520 |
#endif |
| 521 |
} |
| 522 |
|
| 523 |
namespace cwg1881 { // cwg1881: 7 |
| 524 |
struct A { int a : 4; }; |
| 525 |
struct B : A { int b : 3; }; |
| 526 |
static_assert(__is_standard_layout(A), ""); |
| 527 |
static_assert(!__is_standard_layout(B), ""); |
| 528 |
|
| 529 |
struct C { int : 0; }; |
| 530 |
struct D : C { int : 0; }; |
| 531 |
static_assert(__is_standard_layout(C), ""); |
| 532 |
static_assert(!__is_standard_layout(D), ""); |
| 533 |
} |
| 534 |
|
| 535 |
namespace cwg1890 { // cwg1890: no drafting 2018-06-04 |
| 536 |
// FIXME: current consensus for CWG2335 is that the examples are well-formed. |
| 537 |
namespace ex1 { |
| 538 |
#if __cplusplus >= 201402L |
| 539 |
struct A { |
| 540 |
struct B { |
| 541 |
auto foo() { return 0; } // #cwg1890-foo |
| 542 |
}; |
| 543 |
decltype(B().foo()) x; |
| 544 |
// since-cxx14-error@-1 {{function 'foo' with deduced return type cannot be used before it is defined}} |
| 545 |
// since-cxx14-note@#cwg1890-foo {{'foo' declared here}} |
| 546 |
}; |
| 547 |
#endif |
| 548 |
} // namespace ex1 |
| 549 |
|
| 550 |
namespace ex2 { |
| 551 |
#if __cplusplus >= 201103L |
| 552 |
struct Bar { |
| 553 |
struct Baz { |
| 554 |
int a = 0; |
| 555 |
}; |
| 556 |
static_assert(__is_constructible(Baz), ""); |
| 557 |
// since-cxx11-error@-1 {{static assertion failed due to requirement '__is_constructible(cwg1890::ex2::Bar::Baz)'}} |
| 558 |
}; |
| 559 |
#endif |
| 560 |
} // namespace ex2 |
| 561 |
} // namespace cwg1890 |
| 562 |
|
| 563 |
void cwg1891() { // cwg1891: 4 |
| 564 |
#if __cplusplus >= 201103L |
| 565 |
int n; |
| 566 |
auto a = []{}; // #cwg1891-a |
| 567 |
auto b = [=]{ return n; }; // #cwg1891-b |
| 568 |
typedef decltype(a) A; |
| 569 |
typedef decltype(b) B; |
| 570 |
|
| 571 |
static_assert(!__has_trivial_constructor(A), ""); |
| 572 |
// since-cxx20-error@-1 {{failed}} |
| 573 |
static_assert(!__has_trivial_constructor(B), ""); |
| 574 |
|
| 575 |
// C++20 allows default construction for non-capturing lambdas (P0624R2). |
| 576 |
A x; |
| 577 |
// cxx11-17-error@-1 {{no matching constructor for initialization of 'A' (aka '(lambda at}} |
| 578 |
// cxx11-17-note@#cwg1891-a {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided}} |
| 579 |
// cxx11-17-note@#cwg1891-a {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided}} |
| 580 |
B y; |
| 581 |
// since-cxx11-error@-1 {{no matching constructor for initialization of 'B' (aka '(lambda at}} |
| 582 |
// since-cxx11-note@#cwg1891-b {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided}} |
| 583 |
// since-cxx11-note@#cwg1891-b {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided}} |
| 584 |
|
| 585 |
// C++20 allows assignment for non-capturing lambdas (P0624R2). |
| 586 |
a = a; |
| 587 |
// cxx11-17-error-re@-1 {{{{object of type '\(lambda at .+\)' cannot be assigned because its copy assignment operator is implicitly deleted}}}} |
| 588 |
// cxx11-17-note@#cwg1891-a {{lambda expression begins here}} |
| 589 |
a = static_cast<A&&>(a); |
| 590 |
// cxx11-17-error-re@-1 {{{{object of type '\(lambda at .+\)' cannot be assigned because its copy assignment operator is implicitly deleted}}}} |
| 591 |
// cxx11-17-note@#cwg1891-a {{lambda expression begins here}} |
| 592 |
b = b; |
| 593 |
// since-cxx11-error-re@-1 {{{{object of type '\(lambda at .+\)' cannot be assigned because its copy assignment operator is implicitly deleted}}}} |
| 594 |
// since-cxx11-note@#cwg1891-b {{lambda expression begins here}} |
| 595 |
b = static_cast<B&&>(b); |
| 596 |
// since-cxx11-error-re@-1 {{{{object of type '\(lambda at .+\)' cannot be assigned because its copy assignment operator is implicitly deleted}}}} |
| 597 |
// since-cxx11-note@#cwg1891-b {{lambda expression begins here}} |
| 598 |
#endif |
| 599 |
} |
| 600 |
|
| 601 |
namespace cwg1894 { // cwg1894: 3.8 |
| 602 |
// NB: reusing part of cwg407 test |
| 603 |
namespace A { |
| 604 |
struct S {}; |
| 605 |
} |
| 606 |
namespace B { |
| 607 |
typedef int S; |
| 608 |
} |
| 609 |
namespace E { |
| 610 |
typedef A::S S; |
| 611 |
using A::S; |
| 612 |
struct S s; |
| 613 |
} |
| 614 |
namespace F { |
| 615 |
typedef A::S S; |
| 616 |
} |
| 617 |
namespace G { |
| 618 |
using namespace A; |
| 619 |
using namespace F; |
| 620 |
struct S s; |
| 621 |
} |
| 622 |
namespace H { |
| 623 |
using namespace F; |
| 624 |
using namespace A; |
| 625 |
struct S s; |
| 626 |
} |
| 627 |
} |