1393 lines · cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-17,cxx98-14,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx11-20,cxx98-17,cxx11-17,cxx98-14,since-cxx11,cxx11 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx11-20,cxx98-17,cxx11-17,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 %s -verify=expected,cxx11-20,cxx98-17,cxx11-17,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 %s -verify=expected,cxx11-20,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors8 9#if __cplusplus == 199711L10#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)11// cxx98-error@-1 {{variadic macros are a C99 feature}}12#endif13 14namespace cwg600 { // cwg600: 2.815struct S {16 void f(int);17 18private:19 void f(double); // #cwg600-f-double20};21 22void g(S *sp) {23 sp->f(2);24 // access control is applied after overload resolution25 sp->f(2.2);26 // expected-error@-1 {{'f' is a private member of 'cwg600::S'}}27 // expected-note@#cwg600-f-double {{declared private here}}28}29} // namespace cwg60030 31namespace std {32 struct type_info {};33 __extension__ typedef __SIZE_TYPE__ size_t;34} // namespace std35 36namespace cwg601 { // cwg601: 2.737#if __cplusplus >= 201103L38#define MAX __LLONG_MAX__39#else40#define MAX __LONG_MAX__41#endif42 43#if 0x8000 < -144#error 0x8000 should be signed45#endif46 47#if MAX > 0xFFFFFFFF && 0x80000000 < -148#error 0x80000000 should be signed49#endif50 51#if __INT_MAX__ == 0x7FFFFFFF52static_assert(0x80000000 < -1, "0x80000000 should be unsigned");53#endif54 55#if MAX > 0xFFFFFFFFFFFFFFFF && 0x8000000000000000 < -156#error 0x8000000000000000 should be signed57#endif58 59#if __cplusplus >= 201103L && __LLONG_MAX__ == 0x7FFFFFFFFFFFFFFF60static_assert(0x8000000000000000 < -1, "0x8000000000000000 should be unsigned");61#endif62 63#undef MAX64} // namespace cwg60165 66namespace cwg602 { // cwg602: 2.767 template<class T> struct A {68 template<class U> friend struct A;69 };70 71 template<class T> struct B {72 class C {73 template<class U> friend struct B;74 typedef int type;75 };76 typename C::type ct; // ok, befriended77 };78 B<int> b;79} // namespace cwg60280 81namespace cwg603 { // cwg603: 3.182 template<unsigned char> struct S {};83 typedef S<'\001'> S1;84 typedef S<(1ul << __CHAR_BIT__) + 1> S1;85 // since-cxx11-error@-1 {{non-type template argument evaluates to 257, which cannot be narrowed to type 'unsigned char'}}86} // namespace cwg60387 88// cwg604: na89// cwg605 is in cwg605.cpp90 91namespace cwg606 { // cwg606: 3.092#if __cplusplus >= 201103L93 template<typename T> struct S {};94 template<typename T> void f(S<T> &&); // #cwg606-f95 template<typename T> void g(T &&);96 template<typename T> void h(const T &&); // #cwg606-h97 98 void test(S<int> s) {99 f(s);100 // since-cxx11-error@-1 {{no matching function for call to 'f'}}101 // since-cxx11-note@#cwg606-f {{candidate function [with T = int] not viable: expects an rvalue for 1st argument}}102 g(s);103 h(s);104 // since-cxx11-error@-1 {{no matching function for call to 'h'}}105 // since-cxx11-note@#cwg606-h {{candidate function [with T = cwg606::S<int>] not viable: expects an rvalue for 1st argument}}106 107 g(test);108 h(test); // ok, an rvalue reference can bind to a function lvalue109 }110#endif111} // namespace cwg606112 113namespace cwg607 { // cwg607: 2.7114namespace example1 {115struct Y {};116 117template <typename T> struct X : public virtual Y {};118 119template <typename T> class A : public X<T> {120 template <typename S> A(S) : S() {}121};122 123template A<int>::A(Y);124} // namespace example1125 126namespace example2 {127namespace N {128struct B {129 B(int);130};131typedef B typedef_B;132struct D : B {133 D();134};135} // namespace N136 137N::D::D() : typedef_B(0) {}138} // namespace example2139} // namespace cwg607140 141namespace cwg608 { // cwg608: 2.7142 struct A { virtual void f(); };143 struct B : A {};144 struct C : A { void f(); };145 struct D : B, C {};146} // namespace cwg608147 148namespace cwg610 { // cwg610: 2.7149static_assert(-0u == 0u, "");150} // namespace cwg610151 152namespace cwg611 { // cwg611: 2.7153 int k;154 struct S { int &r; } s = { k ? k : k };155} // namespace cwg611156 157// cwg612: na158 159namespace cwg613 { // cwg613: 3.1 c++11160 // see also n2253161 struct A { int n; static void f(); };162 int f(int);163 struct B { virtual void f(); };164 B &g(int);165 166 int an1 = sizeof(A::n);167 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}168 int an2 = sizeof(A::n + 1); // valid per cwg850169 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}170 int an3 = sizeof A::n;171 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}172 int an4 = sizeof(f(A::n));173 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}174 int an5 = sizeof(g(A::n));175 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}176 const std::type_info &an6 = typeid(A::n);177 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}178 const std::type_info &an7 = typeid(A::n + 1);179 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}180 const std::type_info &an8 = typeid(f(A::n));181 // cxx98-error@-1 {{invalid use of non-static data member 'n'}}182 const std::type_info &an9 = typeid(g(A::n));183 // expected-error@-1 {{invalid use of non-static data member 'n'}}184 185 void A::f() {186 int an1 = sizeof n;187 // cxx98-error@-1 {{invalid use of member 'n' in static member function}}188 const std::type_info &an2 = typeid(n + 1);189 // cxx98-error@-1 {{invalid use of member 'n' in static member function}}190 const std::type_info &an3 = typeid(g(n));191 // cxx98-error@-1 {{invalid use of member 'n' in static member function}}192 // since-cxx11-error@-2 {{invalid use of non-static data member 'n'}}193 }194} // namespace cwg613195 196namespace cwg614 { // cwg614: 2.7197static_assert((-1) / 2 == 0, "");198static_assert((-1) % 2 == -1, "");199} // namespace cwg614200 201namespace cwg615 { // cwg615: 2.7202 int f();203 static int n = f();204} // namespace cwg615205 206namespace cwg616 { // cwg616: 4207#if __cplusplus >= 201103L208 struct S { int n; } s;209 S f();210 using T = decltype((S().n));211 using T = decltype((static_cast<S&&>(s).n));212 using T = decltype((f().n));213 using T = decltype(S().*&S::n);214 using T = decltype(static_cast<S&&>(s).*&S::n);215 using T = decltype(f().*&S::n);216 using T = int&&;217 218 using U = decltype(S().n);219 using U = decltype(static_cast<S&&>(s).n);220 using U = int;221#endif222} // namespace cwg616223 224namespace cwg618 { // cwg618: 2.7225#if (unsigned)-1 > 0226#error wrong227#endif228} // namespace cwg618229 230namespace cwg619 { // cwg619: 3.4231 extern int x[10];232 struct S { static int x[10]; };233 234 int x[];235 static_assert(sizeof(x) == sizeof(int) * 10, "");236 extern int x[];237 static_assert(sizeof(x) == sizeof(int) * 10, "");238 239 int S::x[];240 static_assert(sizeof(S::x) == sizeof(int) * 10, "");241 242 void f() {243 extern int x[];244 sizeof(x);245 // expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'int[]'}}246 }247} // namespace cwg619248 249// cwg620: dup 568250 251namespace cwg621 { // cwg621: 2.7252 template<typename T> T f();253 template<> int f() {} // #cwg621-f254 template<> int f<int>() {}255 // expected-error@-1 {{redefinition of 'f<int>'}}256 // expected-note@#cwg621-f {{previous definition is here}}257} // namespace cwg621258 259// cwg623: na260// FIXME: Add documentation saying we allow invalid pointer values.261 262// cwg624 needs a libc++abi test.263 264namespace cwg625 { // cwg625: 2.9265 template<typename T> struct A {};266 A<auto> x = A<int>();267 // cxx98-error@-1 {{'auto' type specifier is a C++11 extension}}268 // expected-error@-2 {{'auto' not allowed in template argument}}269 void f(int);270 void (*p)(auto) = f;271 // cxx98-error@-1 {{'auto' type specifier is a C++11 extension}}272 // expected-error@-2 {{'auto' not allowed in function prototype}}273} // namespace cwg625274 275namespace cwg626 { // cwg626: 2.7276#define STR(x) #x277 char c[2] = STR(c); // ok, type matches278 wchar_t w[2] = STR(w);279 // expected-error@-1 {{initializing wide char array with non-wide string literal}}280} // namespace cwg626281 282namespace cwg627 { // cwg627: 2.7283 void f() {284 // FIXME: emitted diagnostic have a room for improvement285 true a = 0;286 // expected-error@-1 {{expected ';' after expression}}287 // expected-error@-2 {{use of undeclared identifier 'a'}}288 // expected-warning@-3 {{expression result unused}}289 }290} // namespace cwg627291 292// cwg628: na293 294namespace cwg629 { // cwg629: 2.9295 typedef int T;296 int n = 1;297 void f() {298 auto T = 2; // #cwg629-T299 // cxx98-error@-1 {{expected unqualified-id}}300 301 auto T(n);302 // since-cxx11-error@-1 {{redefinition of 'T'}}303 // since-cxx11-note@#cwg629-T {{previous definition is here}}304 }305} // namespace cwg629306 307namespace cwg630 { // cwg630: 2.7308const bool MB_EQ_WC =309 ' ' == L' ' && '\t' == L'\t' && '\v' == L'\v' && '\r' == L'\r' &&310 '\n' == L'\n' && //311 'a' == L'a' && 'b' == L'b' && 'c' == L'c' && 'd' == L'd' && 'e' == L'e' &&312 'f' == L'f' && 'g' == L'g' && 'h' == L'h' && 'i' == L'i' && 'j' == L'j' &&313 'k' == L'k' && 'l' == L'l' && 'm' == L'm' && 'n' == L'n' && 'o' == L'o' &&314 'p' == L'p' && 'q' == L'q' && 'r' == L'r' && 's' == L's' && 't' == L't' &&315 'u' == L'u' && 'v' == L'v' && 'w' == L'w' && 'x' == L'x' && 'y' == L'y' &&316 'z' == L'z' && //317 'A' == L'A' && 'B' == L'B' && 'C' == L'C' && 'D' == L'D' && 'E' == L'E' &&318 'F' == L'F' && 'G' == L'G' && 'H' == L'H' && 'I' == L'I' && 'J' == L'J' &&319 'K' == L'K' && 'L' == L'L' && 'M' == L'M' && 'N' == L'N' && 'O' == L'O' &&320 'P' == L'P' && 'Q' == L'Q' && 'R' == L'R' && 'S' == L'S' && 'T' == L'T' &&321 'U' == L'U' && 'V' == L'V' && 'W' == L'W' && 'X' == L'X' && 'Y' == L'Y' &&322 'Z' == L'Z' && //323 '0' == L'0' && '1' == L'1' && '2' == L'2' && '3' == L'3' && '4' == L'4' &&324 '5' == L'5' && '6' == L'6' && '7' == L'7' && '8' == L'8' &&325 '9' == L'9' && //326 '_' == L'_' && '{' == L'{' && '}' == L'}' && '[' == L'[' && ']' == L']' &&327 '#' == L'#' && '(' == L'(' && ')' == L')' && '<' == L'<' && '>' == L'>' &&328 '%' == L'%' && ':' == L':' && ';' == L';' && '.' == L'.' && '?' == L'?' &&329 '*' == L'*' && '+' == L'+' && '-' == L'-' && '/' == L'/' && '^' == L'^' &&330 '&' == L'&' && '|' == L'|' && '~' == L'~' && '!' == L'!' && '=' == L'=' &&331 ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\'';332#if __STDC_MB_MIGHT_NEQ_WC__333#ifndef __FreeBSD__ // PR22208, FreeBSD expects us to give a bad (but conforming) answer here.334static_assert(!MB_EQ_WC, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters have same representation");335#endif336#else337static_assert(MB_EQ_WC, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs");338#endif339} // namespace cwg630340 341// cwg631: na342 343namespace cwg632 { // cwg632: 2.7344 struct S { int n; } s = {{5}};345 // expected-warning@-1 {{braces around scalar initializer}}346} // namespace cwg632347 348// cwg633: na349// see also n2993350 351namespace cwg634 { // cwg634: 2.7352 struct S { S(); S(const S&); virtual void f(); ~S(); };353 int f(...);354 char f(int);355 template<typename T> int (&g(T))[sizeof f(T())];356 int (&a)[sizeof(int)] = g(S());357 int (&b)[1] = g(0);358 int k = f(S());359 // cxx98-error@-1 {{cannot pass object of non-POD type 'S' through variadic function; call will abort at runtime}}360 // since-cxx11-error@-2 {{cannot pass object of non-trivial type 'S' through variadic function; call will abort at runtime}}361} // namespace cwg634362 363namespace cwg635 { // cwg635: 2.7364 template<typename T> struct A { A(); ~A(); };365 template<typename T> A<T>::A<T>() {}366 // expected-error@-1 {{out-of-line constructor for 'A' cannot have template arguments}}367 template<typename T> A<T>::~A<T>() {}368 369 template<typename T> struct B { B(); ~B(); };370 template<typename T> B<T>::B() {}371 template<typename T> B<T>::~B() {}372 373 struct C { template<typename T> C(); C(); };374 template<typename T> C::C() {}375 C::C() {}376 template<> C::C<int>() {}377 // expected-error@-1 {{qualified reference to 'C' is a constructor name rather than a type in this context}}378 // expected-error@-2 {{expected unqualified-id}}379 /*FIXME: needed for error recovery:*/;380 381 template<typename T> struct D { template<typename U> D(); D(); };382 template<typename T> D<T>::D() {} // #cwg635-D383 template<typename T> template<typename U> D<T>::D() {}384 template<typename T> D<T>::D<T>() {} // #cwg635-D-T385 // expected-error@#cwg635-D-T {{out-of-line constructor for 'D' cannot have template arguments}}386 // expected-error@#cwg635-D-T {{redefinition of 'D<T>'}}387 // expected-note@#cwg635-D {{previous definition is here}}388} // namespace cwg635389 390namespace cwg637 { // cwg637: 3.0391 void f(int i) {392 i = ++i + 1;393 i = i++ + 1;394 // cxx98-14-warning@-1 {{multiple unsequenced modifications to 'i'}}395 }396} // namespace cwg637397 398namespace cwg638 { // cwg638: no399 template<typename T> struct A {400 struct B;401 void f();402 void g();403 struct C {404 void h();405 };406 };407 408 class X {409 typedef int type;410 template<class T> friend struct A<T>::B;411 // expected-warning@-1 {{dependent nested name specifier 'A<T>' for friend class declaration is not supported; turning off access control for 'X'}}412 template<class T> friend void A<T>::f();413 // expected-warning@-1 {{dependent nested name specifier 'A<T>' for friend class declaration is not supported; turning off access control for 'X'}}414 template<class T> friend void A<T>::g();415 // expected-warning@-1 {{dependent nested name specifier 'A<T>' for friend class declaration is not supported; turning off access control for 'X'}}416 template<class T> friend void A<T>::C::h();417 // expected-warning@-1 {{dependent nested name specifier 'A<T>::C' for friend class declaration is not supported; turning off access control for 'X'}}418 };419 420 template<> struct A<int> {421 X::type a; // FIXME: private422 struct B {423 X::type b; // ok424 };425 int f() { X::type c; } // FIXME: private426 void g() { X::type d; } // ok427 struct D {428 void h() { X::type e; } // FIXME: private429 };430 };431} // namespace cwg638432 433namespace cwg639 { // cwg639: 3.3434 void f(int i) {435 void((i = 0) + (i = 0));436 // expected-warning@-1 {{multiple unsequenced modifications to 'i'}}437 }438} // namespace cwg639439 440namespace cwg641 { // cwg641: 2.7441 namespace std_example {442 struct abc;443 444 struct xyz {445 xyz(); // #cwg641-xyz-ctor446 xyz(xyz &); // #cwg641-xyz-copy-ctor447 448 operator xyz &() = delete;449 // expected-warning@-1 {{conversion function converting 'cwg641::std_example::xyz' to itself will never be used}}450 // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}451 operator abc &() = delete;452 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}453 };454 455 struct abc : xyz {};456 457 template<typename T>458 void use(T &); // #cwg641-use459 void test() {460 use<xyz>(xyz());461 // expected-error@-1 {{no matching function for call to 'use'}}462 // expected-note@#cwg641-use {{candidate function template not viable: expects an lvalue for 1st argument}}463 use<const xyz>(xyz());464 // cxx98-error@-1 {{no viable constructor copying parameter of type 'xyz'; C++98 requires a copy constructor when binding a reference to a temporary}}465 // cxx98-note@#cwg641-xyz-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}466 // cxx98-note@#cwg641-xyz-ctor {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}467 }468 }469 470 template<typename T> struct error { typedef typename T::error type; };471 472 struct A {473 template<typename T, typename error<T>::type = 0> operator T() const;474 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}475 };476 A a;477 void f(A&); // #cwg641-f478 void g(const A ca) {479 f(A());480 // expected-error@-1 {{no matching function for call to 'f'}}481 // expected-note@#cwg641-f {{candidate function not viable: expects an lvalue for 1st argument}}482 f(ca);483 // expected-error@-1 {{no matching function for call to 'f'}}484 // expected-note@#cwg641-f {{candidate function not viable: 1st argument ('const A') would lose const qualifier}}485 (void)A();486 (void)ca;487 }488} // namespace cwg641489 490namespace cwg642 { // cwg642: 2.7491 void f() {492 const int i = 2;493 {494 char i[i];495 static_assert(sizeof(i) == 2, "");496 }497 }498 499 struct s { int a; };500 void g(int s) {501 struct s *p = new struct s;502 p->a = s;503 }504} // namespace cwg642505 506namespace cwg643 { // cwg643: 3.2507#if __cplusplus >= 201103L508 struct A {509 int x;510 auto f() -> decltype(this->x);511 auto f(A &a) -> decltype(a.x);512 auto g() -> decltype(x);513 auto h() -> decltype(this->y);514 // since-cxx11-error@-1 {{no member named 'y' in 'cwg643::A'}}515 auto h(A &a) -> decltype(a.y);516 // since-cxx11-error@-1 {{no member named 'y' in 'cwg643::A'}}517 auto i() -> decltype(y);518 // since-cxx11-error@-1 {{use of undeclared identifier 'y'}}519 int y;520 };521#endif522} // namespace cwg643523 524namespace cwg644 { // cwg644: partial525#if __cplusplus >= 201103L526 struct A {527 A() = default;528 int x, y;529 };530 static_assert(__is_literal_type(A), "");531 532 struct B : A {};533 static_assert(__is_literal_type(B), "");534 535 struct C : virtual A {};536 static_assert(!__is_literal_type(C), "");537 538 struct D { C c; };539 static_assert(!__is_literal_type(D), "");540 541 // FIXME: According to CWG644, E<C> is a literal type despite having virtual542 // base classes. This appears to be a wording defect.543 template<typename T>544 struct E : T {545 constexpr E() = default;546 };547 static_assert(!__is_literal_type(E<C>), "");548#endif549} // namespace cwg644550 551// cwg645 increases permission to optimize; it's not clear that it's possible to552// test for this.553// cwg645: na554 555namespace cwg646 { // cwg646: sup 981556#if __cplusplus >= 201103L557 struct A {558 constexpr A(const A&) = default; // ok559 };560 561 struct B {562 constexpr B() {}563 B(B&);564 };565 constexpr B b = {}; // ok566#endif567} // namespace cwg646568 569namespace cwg647 { // cwg647: 3.1570#if __cplusplus >= 201103L571 // This is partially superseded by cwg1358.572 struct A {573 constexpr virtual void f() const;574 constexpr virtual void g() const {}575 // cxx11-17-error@-1 {{virtual function cannot be constexpr}}576 };577 578 struct X { virtual void f() const; }; // #cwg647-f579 struct B : X {580 constexpr void f() const {}581 // cxx11-17-error@-1 {{virtual function cannot be constexpr}}582 // cxx11-17-note@#cwg647-f {{overridden virtual function is here}}583 };584 585 struct NonLiteral { NonLiteral() {} }; // #cwg647-NonLiteral586 587 struct C {588 constexpr C(NonLiteral);589 constexpr C(NonLiteral, int) {}590 // cxx11-20-error@-1 {{constexpr constructor's 1st parameter type 'NonLiteral' is not a literal type}}591 // cxx11-20-note@#cwg647-NonLiteral {{'NonLiteral' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors}}592 constexpr C() try {} catch (...) {}593 // cxx11-17-error@-1 {{function try block in constexpr constructor is a C++20 extension}}594 // cxx11-error@-2 {{use of this statement in a constexpr constructor is a C++14 extension}}595 };596 597 struct D {598 operator int() const;599 constexpr D(int) {}600 D(float); // #cwg647-D-float-ctor601 };602 constexpr int get();603 struct E {604 int n;605 D d;606 607 // FIXME: We should diagnose this, as the conversion function is not608 // constexpr. However, that part of this issue is supreseded by cwg1364 and609 // others; no diagnostic is required for this any more.610 constexpr E()611 : n(D(0)),612 d(0) {}613 614 constexpr E(int)615 // cxx11-20-error@-1 {{constexpr constructor never produces a constant expression}}616 // cxx11-20-note@#cwg647-int-d {{non-constexpr constructor 'D' cannot be used in a constant expression}}617 // cxx11-20-note@#cwg647-D-float-ctor {{declared here}}618 : n(0),619 d(0.0f) {} // #cwg647-int-d620 constexpr E(float f)621 // cxx11-20-error@-1 {{never produces a constant expression}}622 // cxx11-20-note@#cwg647-float-d {{non-constexpr constructor}}623 // cxx11-20-note@#cwg647-D-float-ctor {{declared here}}624 : n(get()),625 d(D(0) + f) {} // #cwg647-float-d626 };627#endif628} // namespace cwg647629 630namespace cwg648 { // cwg648: 2.7631#if __cplusplus >= 201103L632 int f();633 constexpr int a = (true ? 1 : f());634 constexpr int b = false && f();635 constexpr int c = true || f();636#endif637} // namespace cwg648638 639namespace cwg649 { // cwg649: 3.5640#if __cplusplus >= 201103L641// Maximum alignment is 8192 bytes for Windows, and 4 GB for Linux642alignas(0x200000000) int n;643// since-cxx11-error-re@-1 {{{{requested alignment must be (8192|4294967296) bytes or smaller}}}}644struct alignas(0x200000000) X {};645// since-cxx11-error-re@-1 {{{{requested alignment must be (8192|4294967296) bytes or smaller}}}}646struct Y {647 int n alignas(0x200000000);648 // since-cxx11-error-re@-1 {{{{requested alignment must be (8192|4294967296) bytes or smaller}}}}649};650 struct alignas(256) Z {};651 // This part is superseded by cwg2130 and eventually by aligned allocation support.652 auto *p = new Z;653#endif654} // namespace cwg649655 656// cwg650 is in cwg650.cpp657 658namespace cwg651 { // cwg651: 2.7659#if __cplusplus >= 201103L660 struct X {661 virtual X &f();662 };663 struct Y : X {664 Y &f();665 };666 using T = decltype(((X&&)Y()).f());667 using T = X &;668#endif669} // namespace cwg651670 671namespace cwg652 { // cwg652: 3.1672#if __cplusplus >= 201103L673 constexpr int n = 1.2 * 3.4;674 static_assert(n == 4, "");675#endif676} // namespace cwg652677 678// cwg653 is in cwg653.cpp679 680namespace cwg654 { // cwg654: sup 1423681#if __cplusplus >= 201103L682 void f() {683 if (nullptr) {}684 // since-cxx11-warning@-1 {{implicit conversion of nullptr constant to 'bool'}}685 bool b = nullptr;686 // since-cxx11-error@-1 {{cannot initialize a variable of type 'bool' with an rvalue of type 'std::nullptr_t'}}687 if (nullptr == 0) {}688 if (nullptr != 0) {}689 if (nullptr <= 0) {}690 // since-cxx11-error@-1 {{invalid operands to binary expression ('std::nullptr_t' and 'int')}}691 if (nullptr == 1) {}692 // since-cxx11-error@-1 {{invalid operands to binary expression ('std::nullptr_t' and 'int')}}693 if (!nullptr) {}694 // since-cxx11-warning@-1 {{implicit conversion of nullptr constant to 'bool'}}695 decltype(nullptr) n = 0;696 static_cast<int>(nullptr);697 // since-cxx11-error@-1 {{static_cast from 'std::nullptr_t' to 'int' is not allowed}}698 (void)static_cast<decltype(nullptr)>(0);699 static_cast<decltype(nullptr)>(1);700 // since-cxx11-error@-1 {{static_cast from 'int' to 'decltype(nullptr)' (aka 'std::nullptr_t') is not allowed}}701 void(true ? nullptr : 0);702 void(true ? 0 : nullptr);703 }704#endif705} // namespace cwg654706 707namespace cwg655 { // cwg655: 3.0708 struct A { A(int); }; // #cwg655-A709 struct B : A {710 A a; // #cwg655-a711 B();712 B(int) : B() {}713 // cxx98-error@-1 {{delegating constructors are permitted only in C++11}}714 B(int*) : A() {} // #cwg655-delegating-to-A715 // expected-error@-1 {{no matching constructor for initialization of 'A'}}716 // expected-note@#cwg655-A {{candidate constructor not viable: requires 1 argument, but 0 were provided}}717 // expected-note@#cwg655-A {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided}}718 // since-cxx11-note@#cwg655-A {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided}}719 // expected-error@#cwg655-delegating-to-A {{constructor for 'cwg655::B' must explicitly initialize the member 'a' which does not have a default constructor}}720 // expected-note@#cwg655-a {{member is declared here}}721 // expected-note@#cwg655-A {{'cwg655::A' declared here}}722 };723} // namespace cwg655724 725namespace cwg656 { // cwg656: 2.8726 struct A { A(const A&) = delete; };727 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}728 struct B : A {};729 struct X { operator B(); } x;730 const A &r = x;731 struct Y : private A { // #cwg656-Y732 operator B() volatile;733 };734 extern Y y;735 extern volatile Y vy;736 // Conversion not considered due to reference-related types.737 const A &s = y;738 // expected-error@-1 {{cannot cast 'const Y' to its private base class 'const A'}}739 // expected-note@#cwg656-Y {{declared private here}}740 const A &t = vy;741 // expected-error@-1 {{binding reference of type 'const A' to value of type 'volatile Y' drops 'volatile' qualifier}}742 743 struct C { operator struct D(); } c;744 struct D : C {};745 const D &d = c; // ok, D not reference-related to C746 747 template<typename T> void accept(T); // #cwg656-accept-T748 template<typename T> void accept(...) = delete; // #cwg656-accept-var749 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}750 void f() {751 accept<const A&>(x);752 accept<const A&>(y);753 // expected-error@-1 {{cannot cast 'const Y' to its private base class 'const cwg656::A'}}754 // expected-note@#cwg656-Y {{declared private here}}755 accept<const A&>(vy); // #cwg656-vy756 // expected-error@-1 {{call to deleted function 'accept'}}757 // expected-note@#cwg656-accept-var {{candidate function [with T = const cwg656::A &] has been explicitly deleted}}758 // expected-note@#cwg656-accept-T {{candidate function template not viable: no known conversion from 'volatile Y' to 'const A &' for 1st argument}}759 // expected-error@#cwg656-vy {{no matching constructor for initialization of 'volatile Y'}}760 // expected-note@#cwg656-Y {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('volatile Y') would lose volatile qualifier}}761 // expected-note@#cwg656-Y {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}762 accept<const D&>(c);763 }764} // namespace cwg656765 766namespace cwg657 { // cwg657: partial767 struct Abs { virtual void x() = 0; }; // #cwg657-Abs768 struct Der : public Abs { virtual void x(); };769 770 struct Cnvt { template<typename F> Cnvt(F); };771 772 void foo(Cnvt a);773 void foo(Abs &a);774 void f(Abs *a) { foo(*a); }775 776 void bar(Abs &a);777 template<typename T> void bar(T);778 void g(Abs *a) { bar(*a); }779 780 // FIXME: The following examples demonstrate that we might be accepting the781 // above cases for the wrong reason.782 783 struct C { C(Abs) {} };784 // expected-error@-1 {{parameter type 'Abs' is an abstract class}}785 // expected-note@#cwg657-Abs {{unimplemented pure virtual method 'x' in 'Abs'}}786 struct Q { operator Abs() { __builtin_unreachable(); } } q;787 // expected-error@-1 {{return type 'Abs' is an abstract class}}788#if __cplusplus >= 201703L789 // FIXME: We should *definitely* reject this.790 C c = Q().operator Abs();791#endif792 793 template<typename F> struct Cnvt2 { Cnvt2(F); typedef int type; };794 795 // FIXME: We should reject this.796 void baz(Abs &a);797 template<typename T> typename Cnvt2<T>::type baz(T);798 void h(Abs *a) { baz(*a); }799 800 // FIXME: We should reject this too.801 Cnvt2<Abs>::type err;802} // namespace cwg657803 804// cwg658 is in cwg658.cpp805 806namespace cwg659 { // cwg659: 3.0807#if __cplusplus >= 201103L808 static_assert(alignof(char) == alignof(char&), "");809 static_assert(alignof(int) == alignof(int&), "");810 int n = alignof(int(&)());811 // since-cxx11-error@-1 {{invalid application of 'alignof' to a function type}}812 struct A; // #cwg659-A813 int m = alignof(A&);814 // since-cxx11-error@-1 {{invalid application of 'alignof' to an incomplete type 'A'}}815 // since-cxx11-note@#cwg659-A {{forward declaration of 'cwg659::A'}}816#endif817} // namespace cwg659818 819namespace cwg660 { // cwg660: 3.0820#if __cplusplus >= 201103L821 enum : int { a };822 enum class { b };823 // since-cxx11-error@-1 {{scoped enumeration requires a name}}824 auto x = a;825 826 struct X {827 enum : int { a };828 enum class { b };829 // since-cxx11-error@-1 {{scoped enumeration requires a name}}830 };831 auto y = X::a;832#endif833} // namespace cwg660834 835// cwg661 is in cwg661.cpp836 837namespace cwg662 { // cwg662: 2.7838 template <typename T> void f(T t) {839 T &tr = t;840 T *tp = &t;841 // expected-error@-1 {{'tp' declared as a pointer to a reference of type 'int &'}}842 // expected-note@#cwg662-f-call {{in instantiation of function template specialization 'cwg662::f<int &>' requested here}}843#if __cplusplus >= 201103L844 auto *ap = &t;845#endif846 }847 void g(int n) { f<int&>(n); } // #cwg662-f-call848} // namespace cwg662849 850namespace cwg663 { // cwg663: sup P1949851 int ЍЎ = 123;852} // namespace cwg663853 854namespace cwg664 { // cwg664: 2.7855#if __cplusplus >= 201103L856 struct A { A(const A&) = delete; };857 A &&f(A &&a, int n) {858 if (n)859 return f(static_cast<A&&>(a), n - 1);860 return static_cast<A&&>(a);861 }862#endif863} // namespace cwg664864 865namespace cwg665 { // cwg665: 2.8866 struct A { virtual ~A(); };867 struct B : A {} *b;868 struct C : private A {} *c; // #cwg665-C869 struct D : B, C {} *d;870 871 struct VB : virtual A {} *vb;872 struct VC : private virtual A {} *vc; // #cwg665-VC873 struct VD : VB, VC {} *vd;874 875 void f() {876 (void)dynamic_cast<A*>(b);877 (void)dynamic_cast<A*>(c);878 // expected-error@-1 {{cannot cast 'cwg665::C' to its private base class 'cwg665::A'}}879 // expected-note@#cwg665-C {{declared private here}}880 (void)dynamic_cast<A*>(d);881 /* expected-error@-1 {{ambiguous conversion from derived class 'cwg665::D' to base class 'cwg665::A':882 struct cwg665::D -> B -> A883 struct cwg665::D -> C -> A}} */884 (void)dynamic_cast<A*>(vb);885 (void)dynamic_cast<A*>(vc); // emitting diagnostic, even though it could be valid at runtime886 // expected-error@-1 {{cannot cast 'cwg665::VC' to its private base class 'cwg665::A'}}887 // expected-note@#cwg665-VC {{declared private here}}888 (void)dynamic_cast<A*>(vd);889 }890} // namespace cwg665891 892namespace cwg666 { // cwg666: 2.8893 struct P { friend P operator*(P, P); P(int); } p(0);894 895 template<int> int f();896 template<typename T> int f() {897 T::type *p = 0;898 // expected-error@-1 {{missing 'typename' prior to dependent type name 'cwg666::Y::type'}}899 // expected-note@#cwg666-f-Y {{in instantiation of function template specialization 'cwg666::f<cwg666::Y>' requested here}}900 int a(T::type);901 // expected-error@-1 {{missing 'typename' prior to dependent type name 'cwg666::Y::type'}}902 return f<T::type>();903 // expected-error@-1 {{missing 'typename' prior to dependent type name 'cwg666::Y::type'}}904 }905 struct X { static const int type = 0; };906 struct Y { typedef int type; };907 int a = f<X>();908 int b = f<Y>(); // #cwg666-f-Y909} // namespace cwg666910 911// Triviality is entirely different in C++98.912namespace cwg667 { // cwg667: 8913#if __cplusplus >= 201103L914 struct A {915 A() = default; // #cwg667-A-ctor916 // since-cxx11-warning@-1 {{explicitly defaulted default constructor is implicitly deleted}}917 // since-cxx11-note@#cwg667-r {{default constructor of 'A' is implicitly deleted because field 'r' of reference type 'int &' would not be initialized}}918 // since-cxx11-note@#cwg667-A-ctor {{replace 'default' with 'delete'}}919 int &r; // #cwg667-r920 };921 static_assert(!__is_trivially_constructible(A), "");922 923 struct B { ~B() = delete; };924 union C { B b; };925 static_assert(!__is_trivially_destructible(C), "");926 927 struct D { D(const D&) = delete; };928 struct E : D {};929 static_assert(!__is_trivially_constructible(E, const E&), "");930 931 struct F { F &operator=(F&&) = delete; };932 struct G : F {};933 static_assert(!__is_trivially_assignable(G, G&&), "");934#endif935} // namespace cwg667936 937// cwg668 needs an libc++abi test938 939namespace cwg669 { // cwg669: 3.1940#if __cplusplus >= 201103L941 void f() {942 int n;943 using T = decltype(n);944 using T = int;945 using U = decltype((n));946 using U = int &;947 948 [=] {949 using V = decltype(n);950 using V = int;951 using W = decltype((n));952 using W = const int&;953 } ();954 955 struct X {956 int n;957 void f() const {958 using X = decltype(n);959 using X = int;960 using Y = decltype((n));961 using Y = const int&;962 }963 };964 }965#endif966} // namespace cwg669967 968namespace cwg671 { // cwg671: 2.9969 enum class E { e };970 // cxx98-error@-1 {{scoped enumerations are a C++11 extension}}971 E e = static_cast<E>(0);972 int n = static_cast<int>(E::e);973 // cxx98-error@-1 {{use of enumeration in a nested name specifier is a C++11 extension}}974 int m = static_cast<int>(e);975} // namespace cwg671976 977// cwg672 is in cwg672.cpp978 979namespace cwg673 { // cwg673: 2.7980 template<typename> struct X { static const int n = 0; };981 982 class A {983 friend class B *f();984 class C *f();985 void f(class D *);986 enum { e = X<struct E>::n };987 void g() { extern struct FF *p; }988 };989 B *b;990 C *c;991 D *d;992 E *e;993 FF *ff;994 // expected-error@-1 {{unknown type name 'FF'}}995} // namespace cwg673996 997namespace cwg674 { // cwg674: 8998 template<typename T> int f(T);999 1000 int g(int);1001 template<typename T> int g(T);1002 1003 int h(int);1004 template<typename T> int h(T);1005 1006 class X {1007 friend int cwg674::f(int);1008 friend int cwg674::g(int);1009 friend int cwg674::h<>(int);1010 int n; // #cwg674-X-n1011 };1012 1013 template<typename T> int f(T) { return X().n; }1014 int g(int) { return X().n; }1015 template<typename T> int g(T) { return X().n; }1016 // expected-error@-1 {{'n' is a private member of 'cwg674::X'}}1017 // expected-note@#cwg674-g-int {{in instantiation of function template specialization 'cwg674::g<int>' requested here}}1018 // expected-note@#cwg674-X-n {{implicitly declared private here}}1019 int h(int) { return X().n; }1020 // expected-error@-1 {{'n' is a private member of 'cwg674::X'}}1021 // expected-note@#cwg674-X-n {{implicitly declared private here}}1022 template<typename T> int h(T) { return X().n; }1023 1024 template int f(int);1025 template int g(int); // #cwg674-g-int1026 template int h(int);1027 1028 1029 struct Y {1030 template<typename T> int f(T);1031 1032 int g(int);1033 template<typename T> int g(T);1034 1035 int h(int);1036 template<typename T> int h(T);1037 };1038 1039 class Z {1040 friend int Y::f(int);1041 friend int Y::g(int);1042 friend int Y::h<>(int);1043 int n; // #cwg674-Z-n1044 };1045 1046 template<typename T> int Y::f(T) { return Z().n; }1047 int Y::g(int) { return Z().n; }1048 template<typename T> int Y::g(T) { return Z().n; }1049 // expected-error@-1 {{'n' is a private member of 'cwg674::Z'}}1050 // expected-note@#cwg674-Y-g-int {{in instantiation of function template specialization 'cwg674::Y::g<int>' requested here}}1051 // expected-note@#cwg674-Z-n {{implicitly declared private here}}1052 int Y::h(int) { return Z().n; }1053 // expected-error@-1 {{'n' is a private member of 'cwg674::Z'}}1054 // expected-note@#cwg674-Z-n {{implicitly declared private here}}1055 template<typename T> int Y::h(T) { return Z().n; }1056 1057 // FIXME: Should the <> be required here?1058 template int Y::f<>(int);1059 template int Y::g<>(int); // #cwg674-Y-g-int1060 template int Y::h<>(int);1061} // namespace cwg6741062 1063namespace cwg675 { // cwg675: dup 7391064 template<typename T> struct A { T n : 1; };1065#if __cplusplus >= 201103L1066 static_assert(A<char>{1}.n < 0, "");1067 // since-cxx11-warning@-1 {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}1068 static_assert(A<int>{1}.n < 0, "");1069 // since-cxx11-warning@-1 {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}1070 static_assert(A<long long>{1}.n < 0, "");1071 // since-cxx11-warning@-1 {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}1072#endif1073} // namespace cwg6751074 1075// cwg676: na1076 1077namespace cwg677 { // cwg677: no1078 struct A {1079 void *operator new(std::size_t);1080 void operator delete(void*) = delete; // #cwg677-A-delete1081 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}1082 };1083 struct B {1084 void *operator new(std::size_t);1085 void operator delete(void*) = delete; // #cwg677-B-delete1086 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}1087 virtual ~B();1088 };1089 void f(A *p) { delete p; }1090 // expected-error@-1 {{attempt to use a deleted function}}1091 // expected-note@#cwg677-A-delete {{'operator delete' has been explicitly marked deleted here}}1092 // FIXME: This appears to be valid; we shouldn't even be looking up the 'operator delete' here.1093 void f(B *p) { delete p; }1094 // expected-error@-1 {{attempt to use a deleted function}}1095 // expected-note@#cwg677-B-delete {{'operator delete' has been explicitly marked deleted here}}1096 B::~B() {}1097 // expected-error@-1 {{attempt to use a deleted function}}1098 // expected-note@#cwg677-B-delete {{'operator delete' has been explicitly marked deleted here}}1099} // namespace cwg6771100 1101// cwg678 FIXME: check that the modules ODR check catches this1102 1103namespace cwg679 { // cwg679: 2.71104 struct X {};1105 template<int> void operator+(X, X);1106 template<> void operator+<0>(X, X) {} // #cwg679-def1107 template<> void operator+<0>(X, X) {}1108 // expected-error@-1 {{redefinition of 'operator+<0>'}}1109 // expected-note@#cwg679-def {{previous definition is here}}1110} // namespace cwg6791111 1112// cwg680: na1113 1114namespace cwg681 { // cwg681: partial1115#if __cplusplus >= 201103L1116 auto *a() -> int;1117 // since-cxx11-error@-1 {{function with trailing return type must specify return type 'auto', not 'auto *'}}1118 auto (*b)() -> int;1119 // FIXME: The errors here aren't great.1120 auto (*c()) -> int;1121 // since-cxx11-error@-1 {{expected function body after function declarator}}1122 auto ((*d)()) -> int;1123 // since-cxx11-error@-1 {{declaration of variable 'd' with deduced type 'auto ((*)())' requires an initializer}}1124 // since-cxx11-error@-2 {{expected ';' after top level declarator}}1125 1126 // FIXME: This is definitely wrong. This should be1127 // "function of () returning pointer to function of () returning int"1128 // not a function with a deduced return type.1129 auto (*e())() -> int;1130 // cxx11-error@-1 {{'auto' return without trailing return type; deduced return types are a C++14 extension}}1131 1132 auto f() -> int (*)();1133 auto g() -> auto (*)() -> int;1134#endif1135} // namespace cwg6811136 1137namespace cwg683 { // cwg683: 3.31138#if __cplusplus >= 201103L1139 struct A {1140 A() = default;1141 A(const A&) = default;1142 A(A&);1143 };1144 static_assert(__is_trivially_constructible(A, const A&), "");1145 static_assert(!__is_trivially_constructible(A, A&), "");1146 static_assert(!__is_trivial(A), "");1147 1148 struct B : A {};1149 static_assert(__is_trivially_constructible(B, const B&), "");1150 static_assert(__is_trivially_constructible(B, B&), "");1151 static_assert(__is_trivial(B), "");1152#endif1153} // namespace cwg6831154 1155namespace cwg684 { // cwg684: sup 14541156#if __cplusplus >= 201103L1157 void f() {1158 int a; // #cwg684-a1159 constexpr int *p = &a;1160 // since-cxx11-error@-1 {{constexpr variable 'p' must be initialized by a constant expression}}1161 // since-cxx11-note@-2 {{pointer to 'a' is not a constant expression}}1162 // since-cxx11-note@#cwg684-a {{here}}1163 }1164#endif1165} // namespace cwg6841166 1167namespace cwg685 { // cwg685: 101168 enum E : long { e };1169 // cxx98-error@-1 {{enumeration types with a fixed underlying type are a C++11 extension}}1170 void f(int);1171 int f(long);1172 int a = f(e);1173 1174 enum G : short { g };1175 // cxx98-error@-1 {{enumeration types with a fixed underlying type are a C++11 extension}}1176 int h(short);1177 void h(long);1178 int b = h(g);1179 1180 int i(int);1181 void i(long);1182 int c = i(g);1183 1184 int j(unsigned int); // #cwg685-j-uint1185 void j(long); // #cwg685-j-long1186 int d = j(g);1187 // expected-error@-1 {{call to 'j' is ambiguous}}1188 // expected-note@#cwg685-j-uint {{candidate function}}1189 // expected-note@#cwg685-j-long {{candidate function}}1190 1191 // Valid per cwg16011192 int k(short);1193 void k(int);1194 int x = k(g);1195} // namespace cwg6851196 1197namespace cwg686 { // cwg686: 3.01198 void f() {1199 (void)dynamic_cast<struct A*>(0);1200 // expected-error@-1 {{'A' is an incomplete type}}1201 // expected-note@-2 {{forward declaration of 'A'}}1202 (void)dynamic_cast<struct A{}*>(0);1203 // expected-error@-1 {{'A' cannot be defined in a type specifier}}1204 (void)typeid(struct B*);1205 (void)typeid(struct B{}*);1206 // expected-error@-1 {{'B' cannot be defined in a type specifier}}1207 (void)static_cast<struct C*>(0);1208 (void)static_cast<struct C{}*>(0);1209 // expected-error@-1 {{'C' cannot be defined in a type specifier}}1210 (void)reinterpret_cast<struct D*>(0);1211 (void)reinterpret_cast<struct D{}*>(0);1212 // expected-error@-1 {{'D' cannot be defined in a type specifier}}1213 (void)const_cast<struct E*>(0);1214 // expected-error@-1 {{const_cast from 'int' to 'struct E *' is not allowed}}1215 (void)const_cast<struct E{}*>(0);1216 // expected-error@-1 {{'E' cannot be defined in a type specifier}}1217 (void)sizeof(struct F*);1218 (void)sizeof(struct F{}*);1219 // expected-error@-1 {{'F' cannot be defined in a type specifier}}1220 (void)new struct G*; // #cwg686-G1221 (void)new struct G{}*; // #cwg686-G-def1222 // expected-error@-1 {{allocation of incomplete type 'struct G'}}1223 // expected-note@#cwg686-G {{forward declaration of 'G'}}1224 // since-cxx11-error@#cwg686-G-def {{expected expression}}1225#if __cplusplus >= 201103L1226 (void)alignof(struct H*);1227 (void)alignof(struct H{}*);1228 // since-cxx11-error@-1 {{'H' cannot be defined in a type specifier}}1229#endif1230 (void)(struct I*)0;1231 (void)(struct I{}*)0;1232 // expected-error@-1 {{'I' cannot be defined in a type specifier}}1233 if (struct J *p = 0) {}1234 if (struct J {} *p = 0) {}1235 // expected-error@-1 {{'J' cannot be defined in a condition}}1236 for (struct K *p = 0; struct L *q = 0; ) {}1237 for (struct K {} *p = 0; struct L {} *q = 0; ) {}1238 // expected-error@-1 {{'L' cannot be defined in a condition}}1239#if __cplusplus >= 201103L1240 using M = struct {};1241#endif1242 struct N {1243 operator struct O{}(){};1244 // expected-error@-1 {{'cwg686::f()::N::O' cannot be defined in a type specifier}}1245 };1246 try {}1247 catch (struct P *) {}1248 // expected-error@-1 {{cannot catch pointer to incomplete type 'struct P'}}1249 // expected-note@-2 {{forward declaration of 'P'}}1250 catch (struct P {} *) {}1251 // expected-error@-1 {{'P' cannot be defined in a type specifier}}1252#if __cplusplus <= 201402L1253 void g() throw(struct Q);1254 // cxx98-14-error@-1 {{incomplete type 'struct Q' is not allowed in exception specification}}1255 // cxx98-14-note@-2 {{forward declaration of 'Q'}}1256 void h() throw(struct Q {});1257 // cxx98-14-error@-1 {{'Q' cannot be defined in a type specifier}}1258#endif1259 }1260 template<struct R *> struct X;1261 template<struct R {} *> struct Y;1262 // expected-error@-1 {{'cwg686::R' cannot be defined in a type specifier}}1263} // namespace cwg6861264 1265namespace cwg687 { // cwg687 (9 c++20, but the issue is still considered open)1266 template<typename T> void f(T a) {1267 // This is valid in C++20.1268 g<int>(a);1269 // cxx98-17-error@-1 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}1270 1271 // This is not.1272 template g<int>(a);1273 // expected-error@-1 {{expected '<' after 'template'}}1274 }1275} // namespace cwg6871276 1277namespace cwg692 { // cwg692: 161278 // Also see cwg1395.1279 1280 namespace temp_func_order_example2 {1281 template <typename... T> struct A1 {};1282 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1283 template <typename U, typename... T> struct A2 {};1284 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1285 template <typename T1, typename... U> void e1(A1<T1, U...>) = delete;1286 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1287 // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}1288 template <typename T1> void e1(A1<T1>);1289 template <typename T1, typename... U> void e2(A2<T1, U...>) = delete;1290 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1291 // cxx98-error@-2 {{deleted function definitions are a C++11 extension}}1292 template <typename T1> void e2(A2<T1>);1293 template <typename T, typename U> void f(U, A1<U, T> *p = 0) = delete; // #cwg692-f-deleted1294 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}1295 template <typename U> int &f(U, A1<U, U> *p = 0); // #cwg692-f1296 template <typename T> void g(T, T = T()); // #cwg692-g1297 template <typename T, typename... U> void g(T, U...); // #cwg692-g-variadic1298 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1299 void h() {1300 A1<int, int> a;1301 int &r = f<int>(42, &a);1302 A1<int> b1;1303 e1(b1);1304 A2<int> b2;1305 e2(b2);1306 f<int>(42);1307 // expected-error@-1 {{call to 'f' is ambiguous}}1308 // expected-note@#cwg692-f-deleted {{candidate function [with T = int, U = int] has been explicitly deleted}}1309 // expected-note@#cwg692-f {{candidate function [with U = int]}}1310 g(42);1311 // expected-error@-1 {{ambiguous}}1312 // expected-note@#cwg692-g {{candidate function [with T = int]}}1313 // expected-note@#cwg692-g-variadic {{candidate function [with T = int, U = <>]}}1314 }1315 }1316 1317 namespace temp_func_order_example3 {1318 template <typename T, typename... U> void f(T, U...);1319 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1320 template <typename T> void f(T);1321 template <typename T, typename... U> int &g(T *, U...);1322 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1323 template <typename T> void g(T);1324 void h(int i) {1325 // This is made ambiguous by cwg692, but made valid again by cwg1395.1326 f(&i);1327 int &r = g(&i);1328 }1329 }1330 1331 namespace temp_deduct_partial_example {1332 template <typename... Args> char &f(Args... args);1333 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1334 template <typename T1, typename... Args> short &f(T1 a1, Args... args);1335 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1336 template <typename T1, typename T2> int &f(T1 a1, T2 a2);1337 void g() {1338 char &a = f();1339 short &b = f(1, 2, 3);1340 int &c = f(1, 2);1341 }1342 }1343 1344 namespace temp_deduct_type_example1 {1345 template <class T1, class ...Z> class S;1346 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1347 template <class T1, class ...Z> class S<T1, const Z&...>;1348 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1349 template <class T1, class T2> class S<T1, const T2&> {};1350 S<int, const int&> s;1351 1352 template<class T, class... U> struct A;1353 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1354 template<class T1, class T2, class... U> struct A<T1,T2*,U...> {};1355 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1356 template<class T1, class T2> struct A<T1,T2>;1357 template struct A<int, int*>;1358 }1359 1360 namespace temp_deduct_type_example3 {1361 template<class T, class... U> void f(T*, U...){}1362 // cxx98-error@-1 {{variadic templates are a C++11 extension}}1363 template<class T> void f(T){}1364 template void f(int*);1365 }1366} // namespace cwg6921367 1368namespace cwg696 { // cwg696: 3.11369 void f(const int*);1370 void g() {1371 const int N = 10; // #cwg696-N1372 struct A {1373 void h() {1374 int arr[N]; (void)arr;1375 f(&N);1376 // expected-error@-1 {{reference to local variable 'N' declared in enclosing function 'cwg696::g'}}1377 // expected-note@#cwg696-N {{'N' declared here}}1378 }1379 };1380#if __cplusplus >= 201103L1381 (void) [] { int arr[N]; (void)arr; };1382 (void)[] { f(&N); };1383 // since-cxx11-error@-1 {{variable 'N' cannot be implicitly captured in a lambda with no capture-default specified}}1384 // since-cxx11-note@#cwg696-N {{'N' declared here}}1385 // since-cxx11-note@-3 {{lambda expression begins here}}1386 // since-cxx11-note@-4 {{capture 'N' by value}}1387 // since-cxx11-note@-5 {{capture 'N' by reference}}1388 // since-cxx11-note@-6 {{default capture by value}}1389 // since-cxx11-note@-7 {{default capture by reference}}1390#endif1391 }1392} // namespace cwg6961393