1471 lines · cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors8 9// FIXME: diagnostic above is emitted only on Windows platforms10// PR13819 -- __SIZE_TYPE__ is incompatible.11typedef __SIZE_TYPE__ size_t;12// cxx98-error@-1 0-1 {{'long long' is a C++11 extension}}13 14#if __cplusplus == 199711L15#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)16// cxx98-error@-1 {{variadic macros are a C99 feature}}17#endif18 19#if __cplusplus == 199711L20#define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))21#else22#define __enable_constant_folding23#endif24 25namespace cwg200 { // cwg200: dup 21426 template <class T> T f(int);27 template <class T, class U> T f(U) = delete;28 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}29 30 void g() {31 f<int>(1);32 }33} // namespace cwg20034 35// cwg201 is in cwg201.cpp36 37namespace cwg202 { // cwg202: 3.138 template<typename T> T f();39 template<int (*g)()> struct X {40 static_assert(__enable_constant_folding(g == &f<int>), "");41 };42 template struct X<f>;43} // namespace cwg20244 45namespace cwg203 { // cwg203: 3.046namespace ex1 {47struct B {48 int i;49};50struct D1 : B {};51struct D2 : B {};52 53int(D1::*pmD1) = &D2::i;54} // namespace ex155 56#if __cplusplus >= 202002L57namespace ex2 {58struct A {59 int i;60 virtual void f() = 0; // #cwg203-ex2-A-f61};62 63struct B : A {64 int j;65 constexpr B() : j(5) {}66 virtual void f();67};68 69struct C : B {70 constexpr C() { j = 10; }71};72 73template <class T>74constexpr int DefaultValue(int(T::*m)) {75 return T().*m;76 // since-cxx20-error@-1 {{allocating an object of abstract class type 'cwg203::ex2::A'}}77 // since-cxx20-note@#cwg203-ex2-a {{in instantiation of function template specialization 'cwg203::ex2::DefaultValue<cwg203::ex2::A>' requested here}}78 // since-cxx20-note@#cwg203-ex2-A-f {{unimplemented pure virtual method 'f' in 'A'}}79} // #cwg203-ex2-DefaultValue80 81int a = DefaultValue(&B::i); // #cwg203-ex2-a82static_assert(DefaultValue(&C::j) == 5, "");83} // namespace ex284#endif85 86namespace ex3 {87class Base {88public:89 int func() const;90};91 92class Derived : public Base {};93 94template <class T> class Templ { // #cwg203-ex3-Templ95public:96 template <class S> Templ(S (T::*ptmf)() const); // #cwg203-ex3-Templ-ctor97};98 99void foo() { Templ<Derived> x(&Derived::func); }100// expected-error@-1 {{no matching constructor for initialization of 'Templ<Derived>'}}101// expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int (Derived::*)() const' (aka 'int (cwg203::ex3::Base::*)() const') to 'const Templ<cwg203::ex3::Derived>' for 1st argument}}102// since-cxx11-note@#cwg203-ex3-Templ {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int (Derived::*)() const' (aka 'int (cwg203::ex3::Base::*)() const') to 'Templ<cwg203::ex3::Derived>' for 1st argument}}103// expected-note@#cwg203-ex3-Templ-ctor {{candidate template ignored: could not match 'cwg203::ex3::Derived' against 'cwg203::ex3::Base'}}104} // namespace ex3105 106namespace ex4 {107struct Very_base {108 int a;109};110struct Base1 : Very_base {};111struct Base2 : Very_base {};112struct Derived : Base1, Base2 {113};114 115int f() {116 Derived d;117 // FIXME: in the diagnostic below, Very_base is fully qualified, but Derived is not118 int Derived::*a_ptr = &Derived::Base1::a;119 /* expected-error@-1120 {{ambiguous conversion from pointer to member of base class 'cwg203::ex4::Very_base' to pointer to member of derived class 'Derived':121 struct cwg203::ex4::Derived -> Base1 -> Very_base122 struct cwg203::ex4::Derived -> Base2 -> Very_base}}*/123}124} // namespace ex4125 126namespace ex5 {127struct Base {128 int a;129};130struct Derived : Base {131 int b;132};133 134template <typename Class, typename Member_type, Member_type Base::*ptr>135Member_type get(Class &c) {136 return c.*ptr;137}138 139void call(int (*f)(Derived &)); // #cwg203-ex5-call140 141int f() {142 // ill-formed, contrary to Core issue filing:143 // `&Derived::b` yields `int Derived::*`, which can't initialize NTTP of type `int Base::*`,144 // because (implicit) pointer-to-member conversion doesn't upcast.145 call(&get<Derived, int, &Derived::b>);146 // expected-error@-1 {{no matching function for call to 'call'}}147 // expected-note@#cwg203-ex5-call {{candidate function not viable: no overload of 'get' matching 'int (*)(Derived &)' for 1st argument}}148 149 // well-formed, contrary to Core issue filing:150 // `&Derived::a` yields `int Base::*`,151 // which can initialize NTTP of type `int Base::*`.152 call(&get<Derived, int, &Derived::a>);153 154 call(&get<Base, int, &Derived::a>);155 // expected-error@-1 {{no matching function for call to 'call'}}156 // expected-note@#cwg203-ex5-call {{candidate function not viable: no overload of 'get' matching 'int (*)(Derived &)' for 1st argument}}157}158} // namespace ex5159 160namespace ex6 {161struct Base {162 int a;163};164struct Derived : private Base { // #cwg203-ex6-Derived165public:166 using Base::a; // make `a` accessible167};168 169int f() {170 Derived d;171 int b = d.a;172 // FIXME: in the diagnostic below, Base is fully qualified, but Derived is not173 int Derived::*ptr = &Derived::a;174 // expected-error@-1 {{cannot cast private base class 'cwg203::ex6::Base' to 'Derived'}}175 // expected-note@#cwg203-ex6-Derived {{declared private here}}176}177} // namespace ex6178} // namespace cwg203179 180// cwg204: sup 820181 182namespace cwg206 { // cwg206: 2.7183 struct S; // #cwg206-S184 template<typename T> struct Q { S s; };185 // expected-error@-1 {{field has incomplete type 'S'}}186 // expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}187 template<typename T> void f() { S s; }188 // expected-error@-1 {{variable has incomplete type 'S'}}189 // expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}190} // namespace cwg206191 192namespace cwg207 { // cwg207: 2.7193 class A {194 protected:195 static void f() {}196 };197 class B : A {198 public:199 using A::f;200 void g() {201 A::f();202 f();203 }204 };205} // namespace cwg207206 207// cwg208 FIXME: write codegen test208 209namespace cwg209 { // cwg209: 3.2210 class A {211 void f(); // #cwg209-A-f212 };213 class B {214 friend void A::f();215 // expected-error@-1 {{friend function 'f' is a private member of 'cwg209::A'}}216 // expected-note@#cwg209-A-f {{implicitly declared private here}}217 };218} // namespace cwg209219 220// cwg210 is in cwg210.cpp221 222namespace cwg211 { // cwg211: 2.7223 struct A {224 A() try {225 throw 0;226 } catch (...) {227 return;228 // expected-error@-1 {{return in the catch of a function try block of a constructor is illegal}}229 }230 };231} // namespace cwg211232 233namespace cwg212 { // cwg212: 2.7234 template<typename T> struct Base;235 template<typename T> struct Derived;236 237 int *overload(void*);238 float *overload(Base<int>*);239 double *overload(Base<long>*);240 241 void f(Derived<int> *p) {242 // OK, calls void* overload.243 int *a = overload(p);244 245 Base<int> *q = p;246 // expected-error@-1 {{cannot initialize a variable of type 'Base<int> *' with an lvalue of type 'Derived<int> *'}}247 }248 249 template<typename T> struct Base {};250 template<typename T> struct Derived : Base<T> {};251 252 void g(Derived<long> *p) {253 // OK, instantiates and calls Base<long>* overlod.254 double *b = overload(p);255 (void)b;256 }257 258 void h(Derived<float> *p) {259 // OK, instantiates and converts.260 Base<float> *q = p;261 (void)q;262 }263}264 265namespace cwg213 { // cwg213: 2.7266 template <class T> struct A : T {267 void h(T t) {268 char &r1 = f(t);269 int &r2 = g(t);270 // expected-error@-1 {{explicit qualification required to use member 'g' from dependent base class}}271 // expected-note@#cwg213-instantiation {{in instantiation of member function 'cwg213::A<cwg213::B>::h' requested here}}272 // expected-note@#cwg213-B-g {{member is declared here}}273 }274 };275 struct B {276 int &f(B);277 int &g(B); // #cwg213-B-g278 };279 char &f(B);280 281 template void A<B>::h(B); // #cwg213-instantiation282} // namespace cwg213283 284namespace cwg214 { // cwg214: 2.7285 template<typename T, typename U> T checked_cast(U from) { U::error; }286 template<typename T, typename U> T checked_cast(U *from);287 class C {};288 void foo(int *arg) { checked_cast<const C *>(arg); }289 290 template<typename T> T f(int);291 template<typename T, typename U> T f(U) { T::error; }292 void g() {293 f<int>(1);294 }295} // namespace cwg214296 297namespace cwg215 { // cwg215: 2.9298 template<typename T> class X {299 friend void T::foo();300 int n;301 };302 struct Y {303 void foo() { (void)+X<Y>().n; }304 };305} // namespace cwg215306 307namespace cwg216 { // cwg216: no308 // FIXME: Should reject this: 'f' has linkage but its type does not,309 // and 'f' is odr-used but not defined in this TU.310 typedef enum { e } *E;311 void f(E);312 void g(E e) { f(e); }313 314 struct S {315 // FIXME: Should reject this: 'f' has linkage but its type does not,316 // and 'f' is odr-used but not defined in this TU.317 typedef enum { e } *E;318 void f(E);319 };320 void g(S s, S::E e) { s.f(e); }321} // namespace cwg216322 323namespace cwg217 { // cwg217: 2.7324 template<typename T> struct S {325 void f(int);326 };327 template<typename T> void S<T>::f(int = 0) {}328 // expected-error@-1 {{default arguments cannot be added to an out-of-line definition of a member of a class template}}329} // namespace cwg217330 331namespace cwg218 { // cwg218: 2.7332 // NB: also dup 405333 namespace A {334 struct S {};335 void f(S);336 }337 namespace B {338 struct S {};339 void f(S);340 }341 342 struct C {343 int f;344 void test1(A::S as) { f(as); }345 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}346 void test2(A::S as) { void f(); f(as); }347 // expected-error@-1 {{too many arguments to function call, expected 0, have 1}}348 // expected-note@-2 {{'f' declared here}}349 void test3(A::S as) { using A::f; f(as); } // ok350 void test4(A::S as) { using B::f; f(as); } // ok351 void test5(A::S as) { int f; f(as); }352 // expected-error@-1 {{called object type 'int' is not a function or function pointer}}353 void test6(A::S as) { struct f {}; (void) f(as); }354 // expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}}355 // expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}}356 // since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}}357 // expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}358 };359 360 namespace D {361 struct S {};362 struct X { void operator()(S); } f;363 }364 void testD(D::S ds) { f(ds); }365 // expected-error@-1 {{use of undeclared identifier 'f'}}366 367 namespace E {368 struct S {};369 struct f { f(S); };370 }371 void testE(E::S es) { f(es); }372 // expected-error@-1 {{use of undeclared identifier 'f'}}373 374 namespace F {375 struct S {376 template<typename T> friend void f(S, T) {}377 };378 }379 void testF(F::S fs) { f(fs, 0); }380 381 namespace G {382 namespace X {383 int f;384 struct A {};385 }386 namespace Y {387 template<typename T> void f(T);388 struct B {};389 }390 template<typename A, typename B> struct C {};391 }392 void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); }393} // namespace cwg218394 395// cwg219: na396// cwg220: na397 398namespace cwg221 { // cwg221: 3.6399 struct A { // #cwg221-S400 A &operator=(int&); // #cwg221-S-copy-assign401 A &operator+=(int&);402 static A &operator=(A&, double&);403 // expected-error@-1 {{overloaded 'operator=' cannot be a static member function}}404 static A &operator+=(A&, double&);405 // expected-error@-1 {{overloaded 'operator+=' cannot be a static member function}}406 friend A &operator=(A&, char&);407 // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}408 friend A &operator+=(A&, char&);409 };410 A &operator=(A&, float&);411 // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}412 A &operator+=(A&, float&);413 414 void test(A a, int n, char c, float f) {415 a = n;416 a += n;417 a = c;418 // expected-error@-1 {{no viable overloaded '='}}419 // expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'char' to 'int &' for 1st argument}}420 // since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'char' to 'A' for 1st argument}}421 // expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'char' to 'const A' for 1st argument}}422 a += c;423 a = f;424 // expected-error@-1 {{no viable overloaded '='}}425 // expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'float' to 'int &' for 1st argument}}426 // since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'float' to 'A' for 1st argument}}427 // expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'float' to 'const A' for 1st argument}}428 a += f;429 }430} // namespace cwg221431 432namespace cwg222 { // cwg222: dup 637433 void f(int a, int b, int c, int *x) {434#pragma clang diagnostic push435#pragma clang diagnostic warning "-Wunsequenced"436 void((a += b) += c);437 void((a += b) + (a += c));438 // expected-warning@-1 {{multiple unsequenced modifications to 'a'}}439 440 x[a++] = a;441 // cxx98-14-warning@-1 {{unsequenced modification and access to 'a'}}442 443 a = b = 0; // ok, read and write of 'b' are sequenced444 445 a = (b = a++);446 // cxx98-14-warning@-1 {{multiple unsequenced modifications to 'a'}}447 a = (b = ++a);448#pragma clang diagnostic pop449 }450} // namespace cwg222451 452// cwg223: na453 454namespace cwg224 { // cwg224: 16455 namespace example1 {456 template <class T> class A {457 typedef int type;458 A::type a;459 A<T>::type b;460 A<T*>::type c;461 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T *>::type' is a C++20 extension}}462 ::cwg224::example1::A<T>::type d;463 464 class B {465 typedef int type;466 467 A::type a;468 A<T>::type b;469 A<T*>::type c;470 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T *>::type' is a C++20 extension}}471 ::cwg224::example1::A<T>::type d;472 473 B::type e;474 A<T>::B::type f;475 A<T*>::B::type g;476 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T *>::B::type' is a C++20 extension}}477 typename A<T*>::B::type h;478 };479 };480 481 template <class T> class A<T*> {482 typedef int type;483 A<T*>::type a;484 A<T>::type b;485 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'A<T>::type' is a C++20 extension}}486 };487 488 template <class T1, class T2, int I> struct B {489 typedef int type;490 B<T1, T2, I>::type b1;491 B<T2, T1, I>::type b2;492 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B<T2, T1, I>::type' is a C++20 extension}}493 494 typedef T1 my_T1;495 static const int my_I = I;496 static const int my_I2 = I+0;497 static const int my_I3 = my_I;498 B<my_T1, T2, my_I>::type b3;499 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B<my_T1, T2, my_I>::type' is a C++20 extension}}500 B<my_T1, T2, my_I2>::type b4;501 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B<my_T1, T2, my_I2>::type' is a C++20 extension}}502 B<my_T1, T2, my_I3>::type b5;503 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'B<my_T1, T2, my_I3>::type' is a C++20 extension}}504 };505 }506 507 namespace example2 {508 template <int, typename T> struct X { typedef T type; };509 template <class T> class A {510 static const int i = 5;511 X<i, int>::type w;512 X<A::i, char>::type x;513 X<A<T>::i, double>::type y;514 X<A<T*>::i, long>::type z;515 // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name 'X<A<T *>::i, long>::type' is a C++20 extension}}516 int f();517 };518 template <class T> int A<T>::f() {519 return i;520 }521 }522} // namespace cwg224523 524// cwg225: yes525template<typename T> void cwg225_f(T t) { cwg225_g(t); }526// expected-error@-1 {{call to function 'cwg225_g' that is neither visible in the template definition nor found by argument-dependent lookup}}527// expected-note@#cwg225-f {{in instantiation of function template specialization 'cwg225_f<int>' requested here}}528// expected-note@#cwg225-g {{'cwg225_g' should be declared prior to the call site}}529void cwg225_g(int); // #cwg225-g530template void cwg225_f(int); // #cwg225-f531 532namespace cwg226 { // cwg226: no533 // FIXME: This appears to be wrong: default arguments for function templates534 // are listed as a defect (in c++98) not an extension. EDG accepts them in535 // strict c++98 mode.536 template<typename T = void> void f() {}537 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}538 template<typename T> struct S {539 template<typename U = void> void g();540 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}541 template<typename U> struct X;542 template<typename U> void h();543 };544 template<typename T> template<typename U> void S<T>::g() {}545 template<typename T> template<typename U = void> struct S<T>::X {};546 // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}547 template<typename T> template<typename U = void> void S<T>::h() {}548 // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}549 550 template<typename> void friend_h();551 struct A {552 // FIXME: This is ill-formed.553 template<typename=void> struct friend_B;554 // FIXME: f, h, and i are ill-formed.555 // f is ill-formed because it is not a definition.556 // h and i are ill-formed because they are not the only declarations of the557 // function in the translation unit.558 template<typename=void> void friend_f();559 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}560 template<typename=void> void friend_g() {}561 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}562 template<typename=void> void friend_h() {}563 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}564 template<typename=void> void friend_i() {}565 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}566 };567 template<typename> void friend_i();568 569 template<typename=void, typename X> void foo(X) {}570 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}571 template<typename=void, typename X> struct Foo {};572 // expected-error@-1 {{template parameter missing a default argument}}573 // expected-note@-2 {{previous default template argument defined here}}574 575 template<typename=void, typename X, typename, typename Y> int foo(X, Y);576 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}577 template<typename, typename X, typename=void, typename Y> int foo(X, Y);578 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}579 int x = foo(0, 0);580} // namespace cwg226581 582namespace cwg227 { // cwg227: 2.7583void f(bool b) {584 if (b)585 int n;586 else587 int n;588}589} // namespace cwg227590 591namespace cwg228 { // cwg228: 2.7592 template <class T> struct X {593 void f();594 };595 template <class T> struct Y {596 void g(X<T> x) { x.template X<T>::f(); }597 };598} // namespace cwg228599 600namespace cwg229 { // cwg229: 2.9601 template<typename T> void f();602 template<typename T> void f<T*>() {}603 // expected-error@-1 {{function template partial specialization is not allowed}}604 template<> void f<int>() {}605} // namespace cwg229606 607namespace cwg230 { // cwg230: 3.0608 struct S {609 S() { f(); }610 // expected-warning@-1 {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'cwg230::S'}}611 // expected-note@#cwg230-f {{'f' declared here}}612 virtual void f() = 0; // #cwg230-f613 };614} // namespace cwg230615 616namespace cwg231 { // cwg231: 2.7617 namespace outer {618 namespace inner {619 int i; // #cwg231-i620 }621 void f() { using namespace inner; }622 int j = i;623 // expected-error@-1 {{use of undeclared identifier 'i'; did you mean 'inner::i'?}}624 // expected-note@#cwg231-i {{'inner::i' declared here}}625 }626} // namespace cwg231627 628// 232 is NAD; the desired behavior is described in 2823.629// cwg232: dup 2823630 631// cwg234: na632// cwg235: na633 634namespace cwg236 { // cwg236: 3.2635 void *p = int();636 // cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}}637 // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}}638} // namespace cwg236639 640namespace cwg237 { // cwg237: dup 470641 template<typename T> struct A { void f() { T::error; } };642 template<typename T> struct B : A<T> {};643 template struct B<int>; // ok644} // namespace cwg237645 646namespace cwg239 { // cwg239: 2.7647 namespace NS {648 class T {};649 void f(T);650 float &g(T, int);651 }652 NS::T parm;653 int &g(NS::T, float);654 int main() {655 f(parm);656 float &r = g(parm, 1);657 extern int &g(NS::T, float);658 int &s = g(parm, 1);659 }660} // namespace cwg239661 662// cwg240: dup 616663 664namespace cwg241 { // cwg241: 9665 namespace A {666 struct B {};667 template <int X> void f(); // #cwg241-A-f668 template <int X> void g(B);669 }670 namespace C {671 template <class T> void f(T t); // #cwg241-C-f672 template <class T> void g(T t); // #cwg241-C-g673 }674 void h(A::B b) {675 f<3>(b);676 // expected-error@-1 {{no matching function for call to 'f'}}677 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}678 // cxx98-17-error@-3 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}679 g<3>(b);680 // 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}}681 A::f<3>(b);682 // expected-error@-1 {{no matching function for call to 'f'}}683 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}684 A::g<3>(b);685 C::f<3>(b);686 // expected-error@-1 {{no matching function for call to 'f'}}687 // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}688 C::g<3>(b);689 // expected-error@-1 {{no matching function for call to 'g'}}690 // expected-note@#cwg241-C-g {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}691 using C::f;692 using C::g;693 f<3>(b);694 // expected-error@-1 {{no matching function for call to 'f'}}695 // expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}696 // expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}697 g<3>(b);698 }699} // namespace cwg241700 701namespace cwg243 { // cwg243: 2.8702 struct B;703 struct A {704 A(B); // #cwg243-A705 };706 struct B {707 operator A() = delete; // #cwg243-B708 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}709 } b;710 A a1(b);711 A a2 = b;712 // expected-error@-1 {{conversion from 'struct B' to 'A' is ambiguous}}713 // expected-note@#cwg243-A {{candidate constructor}}714 // expected-note@#cwg243-B {{candidate function has been explicitly deleted}}715} // namespace cwg243716 717namespace cwg244 { // cwg244: 11718 // NB: this test is reused by cwg399719 struct B {}; // #cwg244-B720 struct D : B {};721 722 D D_object;723 typedef B B_alias;724 B* B_ptr = &D_object;725 726 void f() {727 D_object.~B();728 // expected-error@-1 {{destructor type 'B' in object destruction expression does not match the type 'D' of the object being destroyed}}729 // expected-note@#cwg244-B {{type 'B' found by destructor name lookup}}730 D_object.B::~B();731 D_object.D::~B(); // FIXME: Missing diagnostic for this.732 B_ptr->~B();733 B_ptr->~B_alias();734 B_ptr->B_alias::~B();735 B_ptr->B_alias::~B_alias();736 B_ptr->cwg244::~B();737 // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}738 B_ptr->cwg244::~B_alias();739 // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}740 }741 742 template<typename T, typename U>743 void f(T *B_ptr, U D_object) {744 D_object.~B(); // FIXME: Missing diagnostic for this.745 D_object.B::~B();746 D_object.D::~B(); // FIXME: Missing diagnostic for this.747 B_ptr->~B();748 B_ptr->~B_alias();749 B_ptr->B_alias::~B();750 B_ptr->B_alias::~B_alias();751 B_ptr->cwg244::~B();752 // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}753 B_ptr->cwg244::~B_alias();754 // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}755 }756 template void f<B, D>(B*, D);757 758 namespace N {759 template<typename T> struct E {};760 typedef E<int> F;761 }762 void g(N::F f) {763 typedef N::F G; // #cwg244-G764 f.~G();765 f.G::~E();766 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}767 f.G::~F();768 // expected-error@-1 {{undeclared identifier 'F' in destructor name}}769 f.G::~G();770 // This is technically ill-formed; E is looked up in 'N::' and names the771 // class template, not the injected-class-name of the class. But that's772 // probably a bug in the standard.773 f.N::F::~E();774 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}775 // This is valid; we look up the second F in the same scope in which we776 // found the first one, that is, 'N::'.777 f.N::F::~F();778 // This is technically ill-formed; G is looked up in 'N::' and is not found.779 // Rejecting this seems correct, but most compilers accept, so we do also.780 f.N::F::~G();781 // expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}782 // expected-note@#cwg244-G {{type 'G' (aka 'E<int>') found by destructor name lookup}}783 }784 785 // Bizarrely, compilers perform lookup in the scope for qualified destructor786 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose787 // this.788 namespace QualifiedLookupInScope {789 namespace N {790 template <typename> struct S { struct Inner {}; };791 }792 template <typename U> void f(typename N::S<U>::Inner *p) {793 typedef typename N::S<U>::Inner T;794 p->::cwg244::QualifiedLookupInScope::N::S<U>::Inner::~T();795 // expected-error@-1 {{no type named 'T' in 'cwg244::QualifiedLookupInScope::N::S<int>'}}796 // expected-note@#cwg244-f {{in instantiation of function template specialization 'cwg244::QualifiedLookupInScope::f<int>' requested here}}797 }798 template void f<int>(N::S<int>::Inner *); // #cwg244-f799 800 template <typename U> void g(U *p) {801 typedef U T;802 p->T::~T();803 p->U::~T();804 p->::cwg244::QualifiedLookupInScope::N::S<int>::Inner::~T();805 // expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}}806 }807 template void g(N::S<int>::Inner *);808 }809} // namespace cwg244810 811namespace cwg245 { // cwg245: 2.8812 struct S {813 enum E {}; // #cwg245-E814 class E *p;815 // expected-error@-1 {{use of 'E' with tag type that does not match previous declaration}}816 // expected-note@#cwg245-E {{previous use is here}}817 };818} // namespace cwg245819 820namespace cwg246 { // cwg246: 3.2821 struct S {822 S() try { // #cwg246-try823 throw 0;824X: ;825 } catch (int) {826 goto X;827 // expected-error@-1 {{cannot jump from this goto statement to its label}}828 // expected-note@#cwg246-try {{jump bypasses initialization of try block}}829 }830 };831} // namespace cwg246832 833namespace cwg247 { // cwg247: 2.7834 struct A {};835 struct B : A {836 void f();837 void f(int);838 };839 void (A::*f)() = (void (A::*)())&B::f;840 841 struct C {842 void f();843 void f(int);844 };845 struct D : C {};846 void (C::*g)() = &D::f;847 void (D::*h)() = &D::f;848 849 struct E {850 void f();851 };852 struct F : E {853 using E::f;854 void f(int);855 };856 void (F::*i)() = &F::f;857} // namespace cwg247858 859namespace cwg248 { // cwg248: sup P1949860 int \u040d\u040e = 0;861} // namespace cwg248862 863namespace cwg249 { // cwg249: 2.7864 template<typename T> struct X { void f(); };865 template<typename T> void X<T>::f() {}866} // namespace cwg249867 868namespace cwg250 { // cwg250: 2.7869 typedef void (*FPtr)(double x[]);870 871 template<int I> void f(double x[]);872 FPtr fp = &f<3>;873 874 template<int I = 3> void g(double x[]);875 // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}876 FPtr gp = &g<>;877} // namespace cwg250878 879namespace cwg252 { // cwg252: 3.1880 struct A {881 void operator delete(void*); // #cwg252-A882 };883 struct B {884 void operator delete(void*); // #cwg252-B885 };886 struct C : A, B {887 virtual ~C();888 };889 C::~C() {}890 // expected-error@-1 {{member 'operator delete' found in multiple base classes of different types}}891 // expected-note@#cwg252-A {{member found by ambiguous name lookup}}892 // expected-note@#cwg252-B {{member found by ambiguous name lookup}}893 894 struct D {895 void operator delete(void*, int); // #cwg252-D896 virtual ~D();897 };898 D::~D() {}899 // expected-error@-1 {{no suitable member 'operator delete' in 'D'}}900 // expected-note@#cwg252-D {{member 'operator delete' declared here}}901 902 struct E {903 void operator delete(void*, int);904 void operator delete(void*) = delete; // #cwg252-E905 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}906 virtual ~E();907 };908 E::~E() {}909 // expected-error@-1 {{attempt to use a deleted function}}910 // expected-note@#cwg252-E {{'operator delete' has been explicitly marked deleted here}}911 912 struct F {913 // If both functions are available, the first one is a placement delete.914 void operator delete(void*, size_t);915 void operator delete(void*) = delete; // #cwg252-F916 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}917 virtual ~F();918 };919 F::~F() {}920 // expected-error@-1 {{attempt to use a deleted function}}921 // expected-note@#cwg252-F {{'operator delete' has been explicitly marked deleted here}}922 923 struct G {924 void operator delete(void*, size_t);925 virtual ~G();926 };927 G::~G() {}928} // namespace cwg252929 930namespace cwg254 { // cwg254: 2.9931 template<typename T> struct A {932 typedef typename T::type type; // ok even if this is a typedef-name, because933 // it's not an elaborated-type-specifier934 typedef struct T::type foo;935 // expected-error@-1 {{typedef 'type' cannot be referenced with the 'struct' specifier}}936 // expected-note@#cwg254-instantiation {{in instantiation of template class 'cwg254::A<cwg254::C>' requested here}}937 // expected-note@#cwg254-C {{declared here}}938 };939 struct B { struct type {}; };940 struct C { typedef struct {} type; }; // #cwg254-C941 A<B>::type n;942 A<C>::type n; // #cwg254-instantiation943} // namespace cwg254944 945namespace cwg255 { // cwg255: 2.7946struct S {947 void operator delete(void *){}948 void operator delete(void *, int){}949};950void f(S *p) { delete p; }951} // namespace cwg255952 953// cwg256: dup 624954 955namespace cwg257 { // cwg257: 3.4956 struct A { A(int); }; // #cwg257-A957 struct B : virtual A {958 B() {}959 virtual void f() = 0;960 };961 struct C : B {962 C() {}963 };964 struct D : B {965 D() {}966 // expected-error@-1 {{constructor for 'cwg257::D' must explicitly initialize the base class 'A' which does not have a default constructor}}967 // expected-note@#cwg257-A {{'cwg257::A' declared here}}968 void f();969 };970} // namespace cwg257971 972namespace cwg258 { // cwg258: 2.8973 struct A {974 void f(const int);975 template<typename> void g(int);976 float &h() const;977 };978 struct B : A {979 using A::f;980 using A::g;981 using A::h;982 int &f(int);983 template<int> int &g(int); // #cwg258-B-g984 int &h();985 } b;986 int &w = b.f(0);987 int &x = b.g<int>(0);988 // expected-error@-1 {{no matching member function for call to 'g'}}989 // expected-note@#cwg258-B-g {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}990 int &y = b.h();991 float &z = const_cast<const B&>(b).h();992 993 struct C {994 virtual void f(const int) = 0;995 };996 struct D : C {997 void f(int);998 } d;999 1000 struct E {1001 virtual void f() = 0; // #cwg258-E-f1002 };1003 struct F : E {1004 void f() const {}1005 } f;1006 // expected-error@-1 {{variable type 'struct F' is an abstract class}}1007 // expected-note@#cwg258-E-f {{unimplemented pure virtual method 'f' in 'F'}}1008} // namespace cwg2581009 1010namespace cwg259 { // cwg259: 41011 template<typename T> struct A {};1012 template struct A<int>; // #cwg259-A-int1013 template struct A<int>;1014 // expected-error@-1 {{duplicate explicit instantiation of 'A<int>'}}1015 // expected-note@#cwg259-A-int {{previous explicit instantiation is here}}1016 1017 template<> struct A<float>; // #cwg259-A-float1018 template struct A<float>;1019 // expected-warning@-1 {{explicit instantiation of 'A<float>' that occurs after an explicit specialization has no effect}}1020 // expected-note@#cwg259-A-float {{previous template specialization is here}}1021 1022 template struct A<char>; // #cwg259-A-char1023 template<> struct A<char>;1024 // expected-error@-1 {{explicit specialization of 'cwg259::A<char>' after instantiation}}1025 // expected-note@#cwg259-A-char {{explicit instantiation first required here}}1026 1027 template<> struct A<double>;1028 template<> struct A<double>;1029 template<> struct A<double> {}; // #cwg259-A-double1030 template<> struct A<double> {};1031 // expected-error@-1 {{redefinition of 'A<double>'}}1032 // expected-note@#cwg259-A-double {{previous definition is here}}1033 1034 template<typename T> struct B; // #cwg259-B1035 template struct B<int>;1036 // expected-error@-1 {{explicit instantiation of undefined template 'cwg259::B<int>'}}1037 // expected-note@#cwg259-B {{template is declared here}}1038 1039 template<> struct B<float>; // #cwg259-B-float1040 template struct B<float>;1041 // expected-warning@-1 {{explicit instantiation of 'B<float>' that occurs after an explicit specialization has no effect}}1042 // expected-note@#cwg259-B-float {{previous template specialization is here}}1043} // namespace cwg2591044 1045// FIXME: When cwg260 is resolved, also add tests for CWG507.1046 1047namespace cwg261 { // cwg261: no1048#pragma clang diagnostic push1049#pragma clang diagnostic warning "-Wused-but-marked-unused"1050 1051 // FIXME: This is ill-formed, with a diagnostic required, because operator new1052 // and operator delete are inline and odr-used, but not defined in this1053 // translation unit.1054 // We're also missing the -Wused-but-marked-unused diagnostic here.1055 struct A {1056 inline void *operator new(size_t) __attribute__((unused));1057 inline void operator delete(void*) __attribute__((unused));1058 A() {}1059 };1060 1061 // FIXME: This is ill-formed, with a required diagnostic, for the same1062 // reason.1063 struct B {1064 inline void operator delete(void*) __attribute__((unused));1065 ~B() {}1066 };1067 struct C {1068 inline void operator delete(void*) __attribute__((unused));1069 virtual ~C() {}1070 // expected-warning@-1 {{'operator delete' was marked unused but was used}}1071 };1072 1073 struct D {1074 inline void operator delete(void*) __attribute__((unused));1075 };1076 void h() { C::operator delete(0); }1077 // expected-warning@-1 {{'operator delete' was marked unused but was used}}1078 1079#pragma clang diagnostic pop1080} // namespace cwg2611081 1082namespace cwg262 { // cwg262: 2.71083 int f(int = 0, ...);1084 int k = f();1085 int l = f(0);1086 int m = f(0, 0);1087} // namespace cwg2621088 1089namespace cwg263 { // cwg263: 3.31090 struct X {};1091 struct Y {1092#if __cplusplus < 201103L1093 friend X::X() throw();1094 friend X::~X() throw();1095#elif __cplusplus <= 201703L1096 friend constexpr X::X() noexcept;1097 friend X::~X();1098#else1099 friend constexpr X::X() noexcept;1100 friend constexpr X::~X();1101#endif1102 Y::Y();1103 // expected-error@-1 {{extra qualification on member 'Y'}}1104 Y::~Y();1105 // expected-error@-1 {{extra qualification on member '~Y'}}1106 };1107} // namespace cwg2631108 1109// cwg265: dup 3531110// cwg266: na1111// cwg269: na1112// cwg270: na1113 1114namespace cwg272 { // cwg272: 2.71115 struct X {1116 void f() {1117 this->~X();1118 X::~X();1119 ~X();1120 // expected-error@-1 {{invalid argument type 'X' to unary expression}}1121 }1122 };1123} // namespace cwg2721124 1125// cwg273 is in cwg273.cpp1126// cwg274: na1127 1128namespace cwg275 { // cwg275: no1129 namespace N {1130 template <class T> void f(T) {} // #cwg275-N-f1131 template <class T> void g(T) {} // #cwg275-N-g1132 template <> void f(int);1133 template <> void f(char);1134 template <> void f(double);1135 template <> void g(char);1136 }1137 1138 using namespace N;1139 1140 namespace M {1141 template <> void N::f(char) {}1142 // expected-error@-1 {{cannot define or redeclare 'f' here because namespace 'M' does not enclose namespace 'N'}}1143 template <class T> void g(T) {}1144 template <> void g(char) {}1145 // FIXME: this should be rejected in c++98 too1146 template void f(long);1147 // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}1148 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}1149 // FIXME: this should be rejected in c++98 too1150 template void N::f(unsigned long);1151 // since-cxx11-error@-1 {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}1152 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}1153 template void h(long);1154 // expected-error@-1 {{explicit instantiation of 'h' does not refer to a function template, variable template, member function, member class, or static data member}}1155 template <> void f(double) {}1156 // expected-error@-1 {{no function template matches function template specialization 'f'}}1157 }1158 1159 template <class T> void g(T) {} // #cwg275-g1160 1161 template <> void N::f(char) {}1162 template <> void f(int) {}1163 // expected-error@-1 {{no function template matches function template specialization 'f'}}1164 1165 // FIXME: this should be rejected in c++98 too1166 template void f(short);1167 // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}1168 // since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}1169 template void N::f(unsigned short);1170 1171 // FIXME: this should probably be valid. the wording from the issue1172 // doesn't clarify this, but it follows from the usual rules.1173 template void g(int);1174 // expected-error@-1 {{partial ordering for explicit instantiation of 'g' is ambiguous}}1175 // expected-note@#cwg275-g {{explicit instantiation candidate function 'cwg275::g<int>' template here [with T = int]}}1176 // expected-note@#cwg275-N-g {{explicit instantiation candidate function 'cwg275::N::g<int>' template here [with T = int]}}1177 1178 // FIXME: likewise, this should also be valid.1179 template<typename T> void f(T) {} // #cwg275-f1180 template void f(short);1181 // expected-error@-1 {{partial ordering for explicit instantiation of 'f' is ambiguous}}1182 // expected-note@#cwg275-f {{explicit instantiation candidate function 'cwg275::f<short>' template here [with T = short]}}1183 // expected-note@#cwg275-N-f {{explicit instantiation candidate function 'cwg275::N::f<short>' template here [with T = short]}}1184} // namespace cwg2751185 1186// cwg276: na1187 1188namespace cwg277 { // cwg277: 3.11189 typedef int *intp;1190 int *p = intp();1191 static_assert(__enable_constant_folding(!intp()), "");1192} // namespace cwg2771193 1194// cwg279 is in cwg279.cpp1195 1196namespace cwg280 { // cwg280: 2.91197 typedef void f0();1198 typedef void f1(int);1199 typedef void f2(int, int);1200 typedef void f3(int, int, int);1201 struct A {1202 operator f1*(); // #cwg280-A-f11203 operator f2*();1204 };1205 struct B {1206 operator f0*(); // #cwg280-B-f01207 private:1208 operator f3*(); // #cwg280-B-f31209 };1210 struct C {1211 operator f0*(); // #cwg280-C-f01212 operator f1*(); // #cwg280-C-f11213 operator f2*(); // #cwg280-C-f21214 operator f3*(); // #cwg280-C-f31215 };1216 struct D : private A, B { // #cwg280-D1217 operator f2*(); // #cwg280-D-f21218 } d;1219 struct E : C, D {} e;1220 void g() {1221 d(); // ok, public1222 d(0);1223 // expected-error@-1 {{'operator void (*)(int)' is a private member of 'cwg280::A'}}1224 // expected-note@#cwg280-D {{constrained by private inheritance here}}1225 // expected-note@#cwg280-A-f1 {{member is declared here}}1226 d(0, 0); // ok, suppressed by member in D1227 d(0, 0, 0);1228 // expected-error@-1 {{'operator void (*)(int, int, int)' is a private member of 'cwg280::B'}}1229 // expected-note@#cwg280-B-f3 {{declared private here}}1230 e();1231 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}1232 // expected-note@#cwg280-B-f0 {{conversion candidate of type 'void (*)()'}}1233 // expected-note@#cwg280-C-f0 {{conversion candidate of type 'void (*)()'}}1234 e(0);1235 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}1236 // expected-note@#cwg280-A-f1 {{conversion candidate of type 'void (*)(int)'}}1237 // expected-note@#cwg280-C-f1 {{conversion candidate of type 'void (*)(int)'}}1238 e(0, 0);1239 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}1240 // expected-note@#cwg280-C-f2 {{conversion candidate of type 'void (*)(int, int)'}}1241 // expected-note@#cwg280-D-f2 {{conversion candidate of type 'void (*)(int, int)'}}1242 e(0, 0, 0);1243 // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}1244 // expected-note@#cwg280-B-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}1245 // expected-note@#cwg280-C-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}1246 }1247} // namespace cwg2801248 1249namespace cwg281 { // cwg281: no1250 void a();1251 inline void b();1252 1253 void d();1254 inline void e();1255 1256 struct S {1257 friend inline void a(); // FIXME: ill-formed1258 friend inline void b();1259 friend inline void c(); // FIXME: ill-formed1260 friend inline void d() {}1261 friend inline void e() {}1262 friend inline void f() {}1263 };1264} // namespace cwg2811265 1266namespace cwg283 { // cwg283: 2.71267 template<typename T> // #cwg283-template1268 struct S {1269 friend class T;1270 // expected-error@-1 {{declaration of 'T' shadows template parameter}}1271 // expected-note@#cwg283-template {{template parameter is declared here}}1272 class T;1273 // expected-error@-1 {{declaration of 'T' shadows template parameter}}1274 // expected-note@#cwg283-template {{template parameter is declared here}}1275 };1276} // namespace cwg2831277 1278namespace cwg284 { // cwg284: no1279 namespace A {1280 struct X;1281 enum Y {};1282 class Z {};1283 }1284 namespace B {1285 struct W;1286 using A::X;1287 using A::Y;1288 using A::Z;1289 }1290 struct B::V {};1291 // expected-error@-1 {{no struct named 'V' in namespace 'cwg284::B'}}1292 struct B::W {};1293 struct B::X {}; // FIXME: ill-formed1294 enum B::Y e; // ok per cwg4171295 class B::Z z; // ok per cwg4171296 1297 struct C {1298 struct X;1299 enum Y {};1300 class Z {};1301 };1302 struct D : C {1303 struct W;1304 using C::X;1305 using C::Y;1306 using C::Z;1307 };1308 struct D::V {};1309 // expected-error@-1 {{no struct named 'V' in 'cwg284::D'}}1310 struct D::W {};1311 struct D::X {}; // FIXME: ill-formed1312 enum D::Y e2; // ok per cwg4171313 class D::Z z2; // ok per cwg4171314} // namespace cwg2841315 1316namespace cwg285 { // cwg285: 2.71317 template<typename T> void f(T, int); // #cwg285-f-T-int1318 template<typename T> void f(int, T); // #cwg285-f-int-T1319 template<> void f<int>(int, int) {}1320 // expected-error@-1 {{function template specialization 'f' ambiguously refers to more than one function template; explicitly specify additional template arguments to identify a particular function template}}1321 // expected-note@#cwg285-f-int-T {{function template 'cwg285::f<int>' matches specialization [with T = int]}}1322 // expected-note@#cwg285-f-T-int {{function template 'cwg285::f<int>' matches specialization [with T = int]}}1323} // namespace cwg2851324 1325namespace cwg286 { // cwg286: 2.81326 template<class T> struct A {1327 class C {1328 template<class T2> struct B {}; // #cwg286-B1329 };1330 };1331 1332 template<class T>1333 template<class T2>1334 struct A<T>::C::B<T2*> { };1335 1336 A<short>::C::B<int*> absip;1337 // expected-error@-1 {{'B' is a private member of 'cwg286::A<short>::C'}}1338 // expected-note@#cwg286-B {{implicitly declared private here}}1339} // namespace cwg2861340 1341// cwg288: na1342 1343namespace cwg289 { // cwg289: 2.71344 struct A; // #cwg289-A1345 struct B : A {};1346 // expected-error@-1 {{base class has incomplete type}}1347 // expected-note@#cwg289-A {{forward declaration of 'cwg289::A'}}1348 1349 template<typename T> struct C { typename T::error error; };1350 // expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}1351 // expected-note@#cwg289-C-int {{in instantiation of template class 'cwg289::C<int>' requested here}}1352 struct D : C<int> {}; // #cwg289-C-int1353} // namespace cwg2891354 1355// cwg290: na1356// cwg291: dup 3911357// cwg292 is in cwg292.cpp1358 1359namespace cwg294 { // cwg294: no1360 void f() throw(int);1361 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}1362 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}1363 int main() {1364 (void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed in C++14 and before1365 // FIXME: since-cxx17-error@-1 {{static_cast from 'void (*)() throw(int)' to 'void (*)() throw()' is not allowed}}1366 //1367 // Irony: the above is valid in C++17 and beyond, but that's exactly when1368 // we reject it. In C++14 and before, this is ill-formed because an1369 // exception-specification is not permitted in a type-id. In C++17, this is1370 // valid because it's the inverse of a standard conversion sequence1371 // containing a function pointer conversion. (Well, it's actually not valid1372 // yet, as a static_cast is not permitted to reverse a function pointer1373 // conversion, but that is being changed by core issue).1374 (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed in C++14 and before1375 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}1376 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}1377 1378 void (*p)() throw() = f;1379 // cxx98-14-error@-1 {{target exception specification is not superset of source}}1380 // since-cxx17-error@-2 {{cannot initialize a variable of type 'void (*)() throw()' with an lvalue of type 'void () throw(int)': different exception specifications}}1381 void (*q)() throw(int) = f;1382 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}1383 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}1384 }1385} // namespace cwg2941386 1387namespace cwg295 { // cwg295: 3.71388 typedef int f();1389 const f g;1390 // expected-warning@-1 {{'const' qualifier on function type 'f' (aka 'int ()') has no effect}}1391 f &r = g;1392 template<typename T> struct X {1393 const T &f;1394 };1395 X<f> x = {g};1396 1397 typedef int U();1398 typedef const U U;1399 // expected-warning@-1 {{'const' qualifier on function type 'U' (aka 'int ()') has no effect}}1400 1401 typedef int (*V)();1402 typedef volatile U *V;1403 // expected-warning@-1 {{'volatile' qualifier on function type 'U' (aka 'int ()') has no effect}}1404} // namespace cwg2951405 1406namespace cwg296 { // cwg296: 2.71407 struct A {1408 static operator int() { return 0; }1409 // expected-error@-1 {{conversion function must be a non-static member function}}1410 };1411} // namespace cwg2961412 1413namespace cwg298 { // cwg298: 3.11414 struct A {1415 typedef int type;1416 A();1417 ~A();1418 };1419 typedef A B; // #cwg298-B1420 typedef const A C; // #cwg298-C1421 1422 A::type i1;1423 B::type i2;1424 C::type i3;1425 1426 struct A a;1427 struct B b;1428 // expected-error@-1 {{typedef 'B' cannot be referenced with the 'struct' specifier}}1429 // expected-note@#cwg298-B {{declared here}}1430 struct C c;1431 // expected-error@-1 {{typedef 'C' cannot be referenced with the 'struct' specifier}}1432 // expected-note@#cwg298-C {{declared here}}1433 1434 B::B() {}1435 // expected-error@-1 {{a type specifier is required for all declarations}}1436 B::A() {} // ok1437 C::~C() {}1438 // expected-error@-1 {{destructor cannot be declared using a typedef 'C' (aka 'const A') of the class name}}1439 1440 typedef struct D E; // #cwg298-E1441 struct E {};1442 // expected-error@-1 {{definition of type 'E' conflicts with typedef of the same name}}1443 // expected-note@#cwg298-E {{'E' declared here}}1444 1445 struct F {1446 ~F();1447 };1448 typedef const F G;1449 G::~F() {} // ok1450} // namespace cwg2981451 1452namespace cwg299 { // cwg299: 2.8 c++111453 struct S {1454 operator int();1455 };1456 struct T {1457 operator int(); // #cwg299-int1458 operator unsigned short(); // #cwg299-ushort1459 };1460 // FIXME: should this apply to c++98 mode?1461 int *p = new int[S()];1462 // cxx98-error@-1 {{implicit conversion from array size expression of type 'S' to integral type 'int' is a C++11 extension}}1463 int *q = new int[T()]; // #cwg299-q1464 // cxx98-11-error@#cwg299-q {{ambiguous conversion of array size expression of type 'T' to an integral or enumeration type}}1465 // cxx98-11-note@#cwg299-int {{conversion to integral type 'int' declared here}}1466 // cxx98-11-note@#cwg299-ushort {{conversion to integral type 'unsigned short' declared here}}1467 // since-cxx14-error-re@#cwg299-q {{conversion from 'T' to '__size_t' (aka 'unsigned {{long long|long|int}}') is ambiguous}}1468 // since-cxx14-note@#cwg299-int {{candidate function}}1469 // since-cxx14-note@#cwg299-ushort {{candidate function}}1470} // namespace cwg2991471