1477 lines · cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-14 -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-14,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple3// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,cxx98-14,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple4// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple5// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple6// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple7// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple8 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 cwg1 { // cwg1: no15 namespace X { extern "C" void cwg1_f(int a = 1); }16 namespace Y { extern "C" void cwg1_f(int a = 1); }17 using X::cwg1_f; using Y::cwg1_f;18 void g() {19 cwg1_f(0);20 // FIXME: This should be rejected, due to the ambiguous default argument.21 cwg1_f();22 }23 namespace X {24 using Y::cwg1_f;25 void h() {26 cwg1_f(0);27 // FIXME: This should be rejected, due to the ambiguous default argument.28 cwg1_f();29 }30 }31 32 namespace X {33 void z(int);34 }35 void X::z(int = 1) {} // #cwg1-z36 namespace X {37 void z(int = 1);38 // expected-error@-1 {{redefinition of default argument}}39 // expected-note@#cwg1-z {{previous definition is here}}40 }41 42 void i(int = 1);43 void j() {44 void i(int = 1);45 using cwg1::i;46 i(0);47 // FIXME: This should be rejected, due to the ambiguous default argument.48 i();49 }50 void k() {51 using cwg1::i;52 void i(int = 1);53 i(0);54 // FIXME: This should be rejected, due to the ambiguous default argument.55 i();56 }57} // namespace cwg158 59namespace cwg3 { // cwg3: 2.760 template<typename T> struct A {};61 template<typename T> void f(T) { A<T> a; } // #cwg3-f-T62 template void f(int);63 template<> struct A<int> {};64 // expected-error@-1 {{explicit specialization of 'cwg3::A<int>' after instantiation}}65 // expected-note@#cwg3-f-T {{implicit instantiation first required here}}66} // namespace cwg367 68namespace cwg4 { // cwg4: 2.869 extern "C" {70 static void cwg4_f(int) {}71 static void cwg4_f(float) {}72 void cwg4_g(int) {} // #cwg4-g-int73 void cwg4_g(float) {}74 // expected-error@-1 {{conflicting types for 'cwg4_g'}}75 // expected-note@#cwg4-g-int {{previous definition is here}}76 }77} // namespace cwg478 79namespace cwg5 { // cwg5: 3.180 struct A {} a;81 struct B {82 B(const A&);83 B(const B&);84 };85 const volatile B b = a;86 87 struct C { C(C&); };88 struct D : C {};89 struct E { operator D&(); } e;90 const C c = e;91} // namespace cwg592 93// cwg6 is in cwg6.cpp94 95namespace cwg7 { // cwg7: 3.496 class A { public: ~A(); };97 class B : virtual private A {}; // #cwg7-B98 class C : public B {} c; // #cwg7-C99 // expected-error@#cwg7-C {{inherited virtual base class 'A' has private destructor}}100 // expected-note@#cwg7-C {{in implicit default constructor for 'cwg7::C' first required here}}101 // expected-note@#cwg7-B {{declared private here}}102 // expected-error@#cwg7-C {{inherited virtual base class 'A' has private destructor}}103 // expected-note@#cwg7-C {{in implicit destructor for 'cwg7::C' first required here}}104 // expected-note@#cwg7-B {{declared private here}}105 class VeryDerivedC : public B, virtual public A {} vdc;106 107 class X { ~X(); }; // #cwg7-X108 class Y : X { ~Y() {} };109 // expected-error@-1 {{base class 'X' has private destructor}}110 // expected-note@#cwg7-X {{implicitly declared private here}}111 112 namespace PR16370 { // This regressed the first time CWG7 was fixed.113 struct S1 { virtual ~S1(); };114 struct S2 : S1 {};115 struct S3 : S2 {};116 struct S4 : virtual S2 {};117 struct S5 : S3, S4 {118 S5();119 ~S5();120 };121 S5::S5() {}122 }123} // namespace cwg7124 125namespace cwg8 { // cwg8: dup 45126 class A {127 struct U;128 static const int k = 5;129 void f();130 template<typename, int, void (A::*)()> struct T;131 132 T<U, k, &A::f> *g();133 };134 A::T<A::U, A::k, &A::f> *A::g() { return 0; }135} // namespace cwg8136 137namespace cwg9 { // cwg9: 2.8138 struct B {139 protected:140 int m; // #cwg9-m141 friend int R1();142 };143 struct N : protected B { // #cwg9-N144 friend int R2();145 } n;146 int R1() { return n.m; }147 // expected-error@-1 {{'m' is a protected member of 'cwg9::B'}}148 // expected-note@#cwg9-N {{constrained by protected inheritance here}}149 // expected-note@#cwg9-m {{member is declared here}}150 int R2() { return n.m; }151} // namespace cwg9152 153namespace cwg10 { // cwg10: dup 45154 class A {155 struct B {156 A::B *p;157 };158 };159} // namespace cwg10160 161namespace cwg11 { // cwg11: 2.7162 template<typename T> struct A : T {163 using typename T::U;164 U u;165 };166 template<typename T> struct B : T {167 using T::V;168 V v;169 // expected-error@-1 {{unknown type name 'V'}}170 };171 struct X { typedef int U; };172 A<X> ax;173} // namespace cwg11174 175namespace cwg12 { // cwg12: sup 239176 enum E { e };177 E &f(E, E = e);178 void g() {179 int &f(int, E = e);180 // Under CWG12, these call two different functions.181 // Under CWG239, they call the same function.182 int &b = f(e);183 int &c = f(1);184 }185} // namespace cwg12186 187namespace cwg13 { // cwg13: no188 extern "C" void f(int);189 void g(char);190 191 template<typename T> struct A {192 A(void (*fp)(T));193 };194 template<typename T> int h(void (T));195 196 A<int> a1(f); // FIXME: We should reject this.197 A<char> a2(g);198 int a3 = h(f); // FIXME: We should reject this.199 int a4 = h(g);200} // namespace cwg13201 202namespace cwg14 { // cwg14: 3.4203 namespace X { extern "C" int cwg14_f(); }204 namespace Y { extern "C" int cwg14_f(); }205 using namespace X;206 using namespace Y;207 int k = cwg14_f();208 209 class C {210 int k;211 friend int Y::cwg14_f();212 } c;213 namespace Z {214 extern "C" int cwg14_f() { return c.k; }215 }216 217 namespace X { typedef int T; typedef int U; } // #cwg14-X-U218 namespace Y { typedef int T; typedef long U; } // #cwg14-Y-U219 T t; // ok, same type both times220 U u;221 // expected-error@-1 {{reference to 'U' is ambiguous}}222 // expected-note@#cwg14-X-U {{candidate found by name lookup is 'cwg14::X::U'}}223 // expected-note@#cwg14-Y-U {{candidate found by name lookup is 'cwg14::Y::U'}}224} // namespace cwg14225 226namespace cwg15 { // cwg15: 2.7227 template<typename T> void f(int); // #cwg15-f-decl-first228 template<typename T> void f(int = 0);229 // expected-error@-1 {{default arguments cannot be added to a function template that has already been declared}}230 // expected-note@#cwg15-f-decl-first {{previous template declaration is here}}231} // namespace cwg15232 233namespace cwg16 { // cwg16: 2.8234 class A { // #cwg16-A235 void f(); // #cwg16-A-f-decl236 friend class C;237 };238 class B : A {}; // #cwg16-B239 class C : B {240 void g() {241 f();242 // expected-error@-1 {{'f' is a private member of 'cwg16::A'}}243 // expected-note@#cwg16-B {{constrained by implicitly private inheritance here}}244 // expected-note@#cwg16-A-f-decl {{member is declared here}}245 A::f(); // #cwg16-A-f-call246 // expected-error@#cwg16-A-f-call {{'A' is a private member of 'cwg16::A'}}247 // expected-note@#cwg16-B {{constrained by implicitly private inheritance here}}248 // expected-note@#cwg16-A {{member is declared here}}249 // expected-error@#cwg16-A-f-call {{cannot cast 'cwg16::C' to its private base class 'A'}}250 // expected-note@#cwg16-B {{implicitly declared private here}}251 }252 };253} // namespace cwg16254 255namespace cwg17 { // cwg17: 2.7256 class A {257 int n;258 int f();259 struct C;260 };261 struct B : A {} b;262 int A::f() { return b.n; }263 struct A::C : A {264 int g() { return n; }265 };266} // namespace cwg17267 268// cwg18: sup 577269 270namespace cwg19 { // cwg19: 3.1271 struct A {272 int n; // #cwg19-n273 };274 struct B : protected A { // #cwg19-B275 };276 struct C : B {} c;277 struct D : B {278 int get1() { return c.n; }279 // expected-error@-1 {{'n' is a protected member of 'cwg19::A'}}280 // expected-note@#cwg19-B {{constrained by protected inheritance here}}281 // expected-note@#cwg19-n {{member is declared here}}282 int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here283 };284} // namespace cwg19285 286namespace cwg20 { // cwg20: 2.8287 class X {288 public:289 X();290 private:291 X(const X&); // #cwg20-X-ctor292 };293 X &f();294 X x = f();295 // expected-error@-1 {{calling a private constructor of class 'cwg20::X'}}296 // expected-note@#cwg20-X-ctor {{declared private here}}297} // namespace cwg20298 299namespace cwg21 { // cwg21: 3.4300 template<typename T> struct A;301 struct X {302 template<typename T = int> friend struct A;303 // expected-error@-1 {{default template argument not permitted on a friend template}}304 template<typename T = int> friend struct B;305 // expected-error@-1 {{default template argument not permitted on a friend template}}306 };307} // namespace cwg21308 309namespace cwg22 { // cwg22: sup 481310 template<typename cwg22_T = cwg22_T> struct X;311 // expected-error@-1 {{unknown type name 'cwg22_T'}}312 typedef int T;313 template<typename T = T> struct Y;314} // namespace cwg22315 316namespace cwg23 { // cwg23: 2.7317 template<typename T> void f(T, T); // #cwg23-f-T-T318 template<typename T> void f(T, int); // #cwg23-f-T-int319 void g() { f(0, 0); }320 // expected-error@-1 {{call to 'f' is ambiguous}}321 // expected-note@#cwg23-f-T-T {{candidate function [with T = int]}}322 // expected-note@#cwg23-f-T-int {{candidate function [with T = int]}}323} // namespace cwg23324 325// cwg24: na326 327namespace cwg25 { // cwg25: 4328 struct A {329 void f() throw(int);330 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}331 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}332 };333 void (A::*f)() throw (int);334 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}335 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}336 void (A::*g)() throw () = f;337 // cxx98-14-error@-1 {{target exception specification is not superset of source}}338 // since-cxx17-error@-2 {{different exception specifications}}339 void (A::*g2)() throw () = 0;340 void (A::*h)() throw (int, char) = f;341 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}342 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}343 void (A::*i)() throw () = &A::f;344 // cxx98-14-error@-1 {{target exception specification is not superset of source}}345 // since-cxx17-error@-2 {{different exception specifications}}346 void (A::*i2)() throw () = 0;347 void (A::*j)() throw (int, char) = &A::f;348 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}349 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}350 void x() {351 g2 = f;352 // cxx98-14-error@-1 {{target exception specification is not superset of source}}353 // since-cxx17-error@-2 {{different exception specifications}}354 h = f;355 i2 = &A::f;356 // cxx98-14-error@-1 {{target exception specification is not superset of source}}357 // since-cxx17-error@-2 {{different exception specifications}}358 j = &A::f;359 }360} // namespace cwg25361 362namespace cwg26 { // cwg26: 2.7363 struct A { A(A, const A & = A()); };364 // expected-error@-1 {{copy constructor must pass its first argument by reference}}365 struct B {366 B();367 // FIXME: In C++98, we diagnose this twice.368 B(const B &, B = B());369 // cxx98-14-error@-1 {{recursive evaluation of default argument}}370 // cxx98-14-note@-2 {{default argument used here}}371 // cxx98-error@-3 {{recursive evaluation of default argument}}372 // cxx98-note@-4 {{default argument used here}}373 };374 struct C {375 static C &f();376 C(const C &, C = f());377 // expected-error@-1 {{recursive evaluation of default argument}}378 // expected-note@-2 {{default argument used here}}379 };380} // namespace cwg26381 382namespace cwg27 { // cwg27: 2.7383 enum E { e } n;384 E &m = true ? n : n;385} // namespace cwg27386 387// cwg28: na lib388 389namespace cwg29 { // cwg29: 3.4390 void cwg29_f0(); // #cwg29-f0391 void g0() { void cwg29_f0(); }392 extern "C++" void g0_cxx() { void cwg29_f0(); }393 extern "C" void g0_c() { void cwg29_f0(); }394 // expected-error@-1 {{declaration of 'cwg29_f0' has a different language linkage}}395 // expected-note@#cwg29-f0 {{previous declaration is here}}396 397 extern "C" void cwg29_f1(); // #cwg29-f1398 void g1() { void cwg29_f1(); }399 extern "C" void g1_c() { void cwg29_f1(); }400 extern "C++" void g1_cxx() { void cwg29_f1(); }401 // expected-error@-1 {{declaration of 'cwg29_f1' has a different language linkage}}402 // expected-note@#cwg29-f1 {{previous declaration is here}}403 404 void g2() { void cwg29_f2(); } // #cwg29-f2405 extern "C" void cwg29_f2();406 // expected-error@-1 {{declaration of 'cwg29_f2' has a different language linkage}}407 // expected-note@#cwg29-f2 {{previous declaration is here}}408 409 extern "C" void g3() { void cwg29_f3(); } // #cwg29-f3410 extern "C++" void cwg29_f3();411 // expected-error@-1 {{declaration of 'cwg29_f3' has a different language linkage}}412 // expected-note@#cwg29-f3 {{previous declaration is here}}413 414 extern "C++" void g4() { void cwg29_f4(); } // #cwg29-f4415 extern "C" void cwg29_f4();416 // expected-error@-1 {{declaration of 'cwg29_f4' has a different language linkage}}417 // expected-note@#cwg29-f4 {{previous declaration is here}}418 419 extern "C" void g5();420 extern "C++" void cwg29_f5();421 void g5() {422 void cwg29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.423 }424 425 extern "C++" void g6();426 extern "C" void cwg29_f6();427 void g6() {428 void cwg29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.429 }430 431 extern "C" void g7();432 extern "C++" void cwg29_f7(); // #cwg29-f7433 extern "C" void g7() {434 void cwg29_f7();435 // expected-error@-1 {{declaration of 'cwg29_f7' has a different language linkage}}436 // expected-note@#cwg29-f7 {{previous declaration is here}}437 }438 439 extern "C++" void g8();440 extern "C" void cwg29_f8(); // #cwg29-f8441 extern "C++" void g8() {442 void cwg29_f8();443 // expected-error@-1 {{declaration of 'cwg29_f8' has a different language linkage}}444 // expected-note@#cwg29-f8 {{previous declaration is here}}445 }446} // namespace cwg29447 448namespace cwg30 { // cwg30: sup 468 c++11449 struct A {450 template<int> static int f();451 } a, *p = &a;452 // FIXME: It's not clear whether CWG468 applies to C++98 too.453 int x = A::template f<0>();454 // cxx98-error@-1 {{'template' keyword outside of a template}}455 int y = a.template f<0>();456 // cxx98-error@-1 {{'template' keyword outside of a template}}457 int z = p->template f<0>();458 // cxx98-error@-1 {{'template' keyword outside of a template}}459} // namespace cwg30460 461namespace cwg31 { // cwg31: 2.8462 class X {463 private:464 void operator delete(void*); // #cwg31-delete465 };466 // We would call X::operator delete if X() threw (even though it can't,467 // and even though we allocated the X using ::operator delete).468 X *p = new X;469 // expected-error@-1 {{'operator delete' is a private member of 'cwg31::X'}}470 // expected-note@#cwg31-delete {{declared private here}}471} // namespace cwg31472 473// cwg32: na474 475namespace cwg33 { // cwg33: 9476 namespace X { struct S; void f(void (*)(S)); } // #cwg33-f-S477 namespace Y { struct T; void f(void (*)(T)); } // #cwg33-f-T478 void g(X::S);479 template<typename Z> Z g(Y::T);480 void h() { f(&g); }481 // expected-error@-1 {{call to 'f' is ambiguous}}482 // expected-note@#cwg33-f-S {{candidate function}}483 // expected-note@#cwg33-f-T {{candidate function}}484 485 template<typename T> void t(X::S);486 template<typename T, typename U = void> void u(X::S);487 // expected-error@-1 0-1 {{default template arguments for a function template are a C++11 extension}}488 void templ() { f(t<int>); f(u<int>); }489 490 // Even though v<int> cannot select the first overload, ADL considers it491 // and adds namespace Z to the set of associated namespaces, and then picks492 // Z::f even though that function has nothing to do with any associated type.493 namespace Z { struct Q; void f(void(*)()); }494 template<int> Z::Q v();495 template<typename> void v();496 void unrelated_templ() { f(v<int>); }497 498 namespace dependent {499 struct X {};500 template<class T> struct Y {501 friend int operator+(X, void(*)(Y)) {}502 };503 504 template<typename T> void f(Y<T>);505 int use = X() + f<int>;506 // expected-error@-1 {{invalid operands to binary expression ('X' and 'void (Y<int>)')}}507 }508 509 namespace member {510 struct Q {};511 struct Y { friend int operator+(Q, Y (*)()); };512 struct X { template<typename> static Y f(); };513 int m = Q() + X().f<int>; // ok514 int n = Q() + (&(X().f<int>)); // ok515 }516} // namespace cwg33517 518// cwg34: na519// cwg35: dup 178520 521namespace cwg36 { // cwg36: 2.8522namespace example1 {523 namespace A {524 int i;525 }526 527 namespace A1 {528 using A::i;529 using A::i;530 }531 532 void f()533 {534 using A::i;535 using A::i;536 }537}538 539namespace example2 {540 struct A541 {542 int i;543 static int j;544 };545 546 struct B : A { };547 struct C : A { };548 549 struct D : virtual B, virtual C550 {551 using B::i; // #cwg36-ex2-B-i-first552 using B::i;553 // expected-error@-1 {{redeclaration of using declaration}}554 // expected-note@#cwg36-ex2-B-i-first {{previous using declaration}}555 556 using C::i; // #cwg36-ex2-C-i-first557 using C::i;558 // expected-error@-1 {{redeclaration of using declaration}}559 // expected-note@#cwg36-ex2-C-i-first {{previous using declaration}}560 561 using B::j; // #cwg36-ex2-B-j-first562 using B::j;563 // expected-error@-1 {{redeclaration of using declaration}}564 // expected-note@#cwg36-ex2-B-j-first {{previous using declaration}}565 566 using C::j; // #cwg36-ex2-C-j-first567 using C::j;568 // expected-error@-1 {{redeclaration of using declaration}}569 // expected-note@#cwg36-ex2-C-j-first {{previous using declaration}}570 };571}572 573namespace example3 {574 template<typename T>575 struct A576 {577 T i;578 static T j;579 };580 581 template<typename T>582 struct B : A<T> { };583 template<typename T>584 struct C : A<T> { };585 586 template<typename T>587 struct D : virtual B<T>, virtual C<T>588 {589 using B<T>::i; // #cwg36-ex3-B-i-first590 using B<T>::i;591 // expected-error@-1 {{redeclaration of using declaration}}592 // expected-note@#cwg36-ex3-B-i-first {{previous using declaration}}593 594 using C<T>::i; // #cwg36-ex3-C-i-first595 using C<T>::i;596 // expected-error@-1 {{redeclaration of using declaration}}597 // expected-note@#cwg36-ex3-C-i-first {{previous using declaration}}598 599 using B<T>::j; // #cwg36-ex3-B-j-first600 using B<T>::j;601 // expected-error@-1 {{redeclaration of using declaration}}602 // expected-note@#cwg36-ex3-B-j-first {{previous using declaration}}603 604 using C<T>::j; // #cwg36-ex3-C-j-first605 using C<T>::j;606 // expected-error@-1 {{redeclaration of using declaration}}607 // expected-note@#cwg36-ex3-C-j-first {{previous using declaration}}608 };609}610namespace example4 {611 template<typename T>612 struct E {613 T k;614 };615 616 template<typename T>617 struct G : E<T> {618 using E<T>::k; // #cwg36-E-k-first619 using E<T>::k;620 // expected-error@-1 {{redeclaration of using declaration}}621 // expected-note@#cwg36-E-k-first {{previous using declaration}}622 };623}624} // namespace cwg36625 626// cwg37: sup 475627 628namespace cwg38 { // cwg38: 2.7629 template<typename T> struct X {};630 template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; }631 template X<int> operator+<int>(X<int>, X<int>);632} // namespace cwg38633 634namespace cwg39 { // cwg39: no635 namespace example1 {636 struct A { int &f(int); };637 struct B : A {638 using A::f;639 float &f(float);640 } b;641 int &r = b.f(0);642 }643 644 namespace example2 {645 struct A {646 int &x(int); // #cwg39-A-x-decl647 static int &y(int); // #cwg39-A-y-decl648 };649 struct V {650 int &z(int);651 };652 struct B : A, virtual V {653 using A::x; // #cwg39-using-A-x654 float &x(float);655 using A::y; // #cwg39-using-A-y656 static float &y(float);657 using V::z;658 float &z(float);659 };660 struct C : A, B, virtual V {} c;661 /* expected-warning@-1662 {{direct base 'A' is inaccessible due to ambiguity:663 struct cwg39::example2::C -> A664 struct cwg39::example2::C -> B -> A}} */665 int &x = c.x(0);666 // expected-error@-1 {{member 'x' found in multiple base classes of different types}}667 // expected-note@#cwg39-A-x-decl {{member found by ambiguous name lookup}}668 // expected-note@#cwg39-using-A-x {{member found by ambiguous name lookup}}669 670 // FIXME: This is valid, because we find the same static data member either way.671 int &y = c.y(0);672 // expected-error@-1 {{member 'y' found in multiple base classes of different types}}673 // expected-note@#cwg39-A-y-decl {{member found by ambiguous name lookup}}674 // expected-note@#cwg39-using-A-y {{member found by ambiguous name lookup}}675 int &z = c.z(0);676 }677 678 namespace example3 {679 struct A { static int f(); };680 struct B : virtual A { using A::f; };681 struct C : virtual A { using A::f; };682 struct D : B, C {} d;683 int k = d.f();684 }685 686 namespace example4 {687 struct A { int n; }; // #cwg39-ex4-A-n688 struct B : A {};689 struct C : A {};690 struct D : B, C { int f() { return n; } };691 /* expected-error@-1692 {{non-static member 'n' found in multiple base-class subobjects of type 'A':693 struct cwg39::example4::D -> B -> A694 struct cwg39::example4::D -> C -> A}} */695 // expected-note@#cwg39-ex4-A-n {{member found by ambiguous name lookup}}696 }697 698 namespace PR5916 {699 // FIXME: This is valid.700 struct A { int n; }; // #cwg39-A-n701 struct B : A {};702 struct C : A {};703 struct D : B, C {};704 int k = sizeof(D::n); // #cwg39-sizeof705 /* expected-error@#cwg39-sizeof706 {{non-static member 'n' found in multiple base-class subobjects of type 'A':707 struct cwg39::PR5916::D -> B -> A708 struct cwg39::PR5916::D -> C -> A}} */709 // expected-note@#cwg39-A-n {{member found by ambiguous name lookup}}710 711 // expected-error@#cwg39-sizeof {{unknown type name}}712#if __cplusplus >= 201103L713 decltype(D::n) n;714 /* since-cxx11-error@-1715 {{non-static member 'n' found in multiple base-class subobjects of type 'A':716 struct cwg39::PR5916::D -> B -> A717 struct cwg39::PR5916::D -> C -> A}} */718 // since-cxx11-note@#cwg39-A-n {{member found by ambiguous name lookup}}719#endif720 }721} // namespace cwg39722 723// cwg40: na724 725namespace cwg41 { // cwg41: 2.7726 struct S f(S);727} // namespace cwg41728 729namespace cwg42 { // cwg42: 2.7730 struct A { static const int k = 0; };731 struct B : A { static const int k = A::k; };732} // namespace cwg42733 734// cwg43: na735 736namespace cwg44 { // cwg44: sup 727737 struct A {738 template<int> void f();739 template<> void f<0>();740 };741} // namespace cwg44742 743namespace cwg45 { // cwg45: 2.7744 class A {745 class B {};746 class C : B {};747 C c;748 };749} // namespace cwg45750 751namespace cwg46 { // cwg46: 2.7752 template<typename> struct A { template<typename> struct B {}; };753 template template struct A<int>::B<int>;754 // expected-error@-1 {{expected unqualified-id}}755} // namespace cwg46756 757namespace cwg47 { // cwg47: sup 329758 template<typename T> struct A {759 friend void f() { T t; } // #cwg47-f760 // expected-error@-1 {{redefinition of 'f'}}761 // expected-note@#cwg47-b {{in instantiation of template class 'cwg47::A<float>' requested here}}762 // expected-note@#cwg47-f {{previous definition is here}}763 };764 A<int> a;765 A<float> b; // #cwg47-b766 767 void f();768 void g() { f(); }769} // namespace cwg47770 771namespace cwg48 { // cwg48: 2.7772 namespace {773 struct S {774 static const int m = 0;775 static const int n = 0;776 static const int o = 0;777 };778 }779 int a = S::m;780 // FIXME: We should produce a 'has internal linkage but is not defined'781 // diagnostic for 'S::n'.782 const int &b = S::n;783 const int S::o;784 const int &c = S::o;785} // namespace cwg48786 787namespace cwg49 { // cwg49: 2.8788 template<int*> struct A {}; // #cwg49-A789 int k;790#if __has_feature(cxx_constexpr)791 constexpr792#endif793 int *const p = &k; // #cwg49-p794 A<&k> a;795 A<p> b; // #cwg49-b796 // cxx98-error@#cwg49-b {{non-type template argument referring to object 'p' with internal linkage is a C++11 extension}}797 // cxx98-note@#cwg49-p {{non-type template argument refers to object here}}798 // cxx98-14-error@#cwg49-b {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}799 // cxx98-14-note@#cwg49-A {{template parameter is declared here}}800 int *q = &k; // #cwg49-q801 A<q> c; // #cwg49-c802 // cxx98-error@#cwg49-c {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}803 // cxx98-note@#cwg49-A {{template parameter is declared here}}804 // cxx11-14-error@#cwg49-c {{non-type template argument of type 'int *' is not a constant expression}}805 // cxx11-14-note@#cwg49-c {{read of non-constexpr variable 'q' is not allowed in a constant expression}}806 // cxx11-14-note@#cwg49-q {{declared here}}807 // cxx11-14-note@#cwg49-A {{template parameter is declared here}}808 // since-cxx17-error@#cwg49-c {{non-type template argument is not a constant expression}}809 // since-cxx17-note@#cwg49-c {{read of non-constexpr variable 'q' is not allowed in a constant expression}}810 // since-cxx17-note@#cwg49-q {{declared here}}811} // namespace cwg49812 813namespace cwg50 { // cwg50: 2.7814 struct X; // #cwg50-X815 extern X *p;816 X *q = (X*)p;817 X *r = static_cast<X*>(p);818 X *s = const_cast<X*>(p);819 X *t = reinterpret_cast<X*>(p);820 X *u = dynamic_cast<X*>(p);821 // expected-error@-1 {{'cwg50::X' is an incomplete type}}822 // expected-note@#cwg50-X {{forward declaration of 'cwg50::X'}}823} // namespace cwg50824 825namespace cwg51 { // cwg51: 2.8826 struct A {};827 struct B : A {};828 struct S {829 operator A&();830 operator B&();831 } s;832 A &a = s;833} // namespace cwg51834 835namespace cwg52 { // cwg52: 2.8836 struct A { int n; }; // #cwg52-A837 struct B : private A {} b; // #cwg52-B838 int k = b.A::n; // #cwg52-k839 // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.840 // expected-error@#cwg52-k {{'A' is a private member of 'cwg52::A'}}841 // expected-note@#cwg52-B {{constrained by private inheritance here}}842 // expected-note@#cwg52-A {{member is declared here}}843 // expected-error@#cwg52-k {{cannot cast 'struct B' to its private base class 'A'}}844 // expected-note@#cwg52-B {{declared private here}}845} // namespace cwg52846 847namespace cwg53 { // cwg53: 2.7848 int n = 0;849 enum E { e } x = static_cast<E>(n);850} // namespace cwg53851 852namespace cwg54 { // cwg54: 2.8853 struct A { int a; } a;854 struct V { int v; } v;855 struct B : private A, virtual V { int b; } b; // #cwg54-B856 857 A &sab = static_cast<A&>(b);858 // expected-error@-1 {{cannot cast 'struct B' to its private base class 'A'}}859 // expected-note@#cwg54-B {{declared private here}}860 A *spab = static_cast<A*>(&b);861 // expected-error@-1 {{cannot cast 'struct B' to its private base class 'A'}}862 // expected-note@#cwg54-B {{declared private here}}863 int A::*smab = static_cast<int A::*>(&B::b);864 // expected-error@-1 {{cannot cast 'cwg54::B' to its private base class 'A'}}865 // expected-note@#cwg54-B {{declared private here}}866 B &sba = static_cast<B&>(a);867 // expected-error@-1 {{cannot cast private base class 'cwg54::A' to 'cwg54::B'}}868 // expected-note@#cwg54-B {{declared private here}}869 B *spba = static_cast<B*>(&a);870 // expected-error@-1 {{cannot cast private base class 'cwg54::A' to 'cwg54::B'}}871 // expected-note@#cwg54-B {{declared private here}}872 int B::*smba = static_cast<int B::*>(&A::a);873 // expected-error@-1 {{cannot cast private base class 'A' to 'B'}}874 // expected-note@#cwg54-B {{declared private here}}875 876 V &svb = static_cast<V&>(b);877 V *spvb = static_cast<V*>(&b);878 int V::*smvb = static_cast<int V::*>(&B::b);879 // expected-error@-1 {{conversion from pointer to member of class 'cwg54::B' to pointer to member of class 'V' via virtual base 'cwg54::V' is not allowed}}880 B &sbv = static_cast<B&>(v);881 // expected-error@-1 {{cannot cast 'struct V' to 'B &' via virtual base 'cwg54::V'}}882 B *spbv = static_cast<B*>(&v);883 // expected-error@-1 {{cannot cast 'cwg54::V *' to 'B *' via virtual base 'cwg54::V'}}884 int B::*smbv = static_cast<int B::*>(&V::v);885 // expected-error@-1 {{conversion from pointer to member of class 'V' to pointer to member of class 'B' via virtual base 'cwg54::V' is not allowed}}886 887 A &cab = (A&)(b);888 A *cpab = (A*)(&b);889 int A::*cmab = (int A::*)(&B::b);890 B &cba = (B&)(a);891 B *cpba = (B*)(&a);892 int B::*cmba = (int B::*)(&A::a);893 894 V &cvb = (V&)(b);895 V *cpvb = (V*)(&b);896 int V::*cmvb = (int V::*)(&B::b);897 // expected-error@-1 {{conversion from pointer to member of class 'cwg54::B' to pointer to member of class 'V' via virtual base 'cwg54::V' is not allowed}}898 B &cbv = (B&)(v);899 // expected-error@-1 {{cannot cast 'struct V' to 'B &' via virtual base 'cwg54::V'}}900 B *cpbv = (B*)(&v);901 // expected-error@-1 {{cannot cast 'cwg54::V *' to 'B *' via virtual base 'cwg54::V'}}902 int B::*cmbv = (int B::*)(&V::v);903 // expected-error@-1 {{conversion from pointer to member of class 'V' to pointer to member of class 'B' via virtual base 'cwg54::V' is not allowed}}904} // namespace cwg54905 906namespace cwg55 { // cwg55: 2.7907 enum E { e = 5 };908 static_assert(e + 1 == 6, "");909} // namespace cwg55910 911namespace cwg56 { // cwg56: 2.7912 struct A {913 typedef int T; // #cwg56-typedef-int-T-first914 typedef int T;915 // expected-error@-1 {{redefinition of 'T'}}916 // expected-note@#cwg56-typedef-int-T-first {{previous definition is here}}917 };918 struct B {919 struct X;920 typedef X X; // #cwg56-typedef-X-X-first921 typedef X X;922 // expected-error@-1 {{redefinition of 'X'}}923 // expected-note@#cwg56-typedef-X-X-first {{previous definition is here}}924 };925} // namespace cwg56926 927namespace cwg58 { // cwg58: 3.1928 // FIXME: Ideally, we should have a CodeGen test for this.929#if __cplusplus >= 201103L930 enum E1 { E1_0 = 0, E1_1 = 1 };931 enum E2 { E2_0 = 0, E2_m1 = -1 };932 struct X { E1 e1 : 1; E2 e2 : 1; };933 static_assert(X{E1_1, E2_m1}.e1 == 1, "");934 static_assert(X{E1_1, E2_m1}.e2 == -1, "");935#endif936} // namespace cwg58937 938namespace cwg59 { // cwg59: 2.7939#pragma clang diagnostic push940#pragma clang diagnostic ignored "-Wdeprecated-volatile"941 template<typename T> struct convert_to { operator T() const; };942 struct A {}; // #cwg59-A943 struct B : A {}; // #cwg59-B944 945 A a1 = convert_to<A>();946 A a2 = convert_to<A&>();947 A a3 = convert_to<const A>();948 A a4 = convert_to<const volatile A>();949 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::A'}}950 // cxx98-14-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::A') would lose volatile qualifier}}951 // cxx11-14-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::A') would lose const and volatile qualifiers}}952 // cxx98-14-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}953 A a5 = convert_to<const volatile A&>();954 // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::A'}}955 // expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::A') would lose volatile qualifier}}956 // since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::A') would lose const and volatile qualifiers}}957 // expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}958 959 B b1 = convert_to<B>();960 B b2 = convert_to<B&>();961 B b3 = convert_to<const B>();962 B b4 = convert_to<const volatile B>();963 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}964 // cxx98-14-note@#cwg59-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::B') would lose volatile qualifier}}965 // cxx11-14-note@#cwg59-B {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::B') would lose const and volatile qualifiers}}966 // cxx98-14-note@#cwg59-B {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}967 B b5 = convert_to<const volatile B&>();968 // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}969 // expected-note@#cwg59-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::B') would lose volatile qualifier}}970 // since-cxx11-note@#cwg59-B {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::B') would lose const and volatile qualifiers}}971 // expected-note@#cwg59-B {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}972 973 A c1 = convert_to<B>();974 A c2 = convert_to<B&>();975 A c3 = convert_to<const B>();976 A c4 = convert_to<const volatile B>();977 // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}978 // expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'const A &' for 1st argument}}979 // since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'A &&' for 1st argument}}980 // expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}981 A c5 = convert_to<const volatile B&>();982 // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}983 // expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'const A &' for 1st argument}}984 // since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'A &&' for 1st argument}}985 // expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}986 987 int n1 = convert_to<int>();988 int n2 = convert_to<int&>();989 int n3 = convert_to<const int>();990 int n4 = convert_to<const volatile int>();991 int n5 = convert_to<const volatile int&>();992#pragma clang diagnostic pop993} // namespace cwg59994 995namespace cwg60 { // cwg60: 2.7996 void f(int &);997 int &f(...);998 const int k = 0;999 int &n = f(k);1000} // namespace cwg601001 1002namespace cwg61 { // cwg61: 3.41003 struct X {1004 static void f();1005 } x;1006 struct Y {1007 static void f();1008 static void f(int);1009 } y;1010 // This is (presumably) valid, because x.f does not refer to an overloaded1011 // function name.1012 void (*p)() = &x.f;1013 void (*q)() = &y.f;1014 // expected-error@-1 {{cannot create a non-constant pointer to member function}}1015 void (*r)() = y.f;1016 // expected-error@-1 {{cannot create a non-constant pointer to member function}}1017} // namespace cwg611018 1019namespace cwg62 { // cwg62: 2.91020 struct A {1021 struct { int n; } b;1022 };1023 template<typename T> struct X {};1024 template<typename T> T get() { return get<T>(); }1025 template<typename T> int take(T) { return 0; }1026 1027 X<A> x1;1028 A a = get<A>();1029 1030 typedef struct { } *NoNameForLinkagePtr; // #cwg62-unnamed1031 NoNameForLinkagePtr noNameForLinkagePtr;1032 1033 struct Danger {1034 NoNameForLinkagePtr p;1035 };1036 1037 X<NoNameForLinkagePtr> x2;1038 // cxx98-error@-1 {{template argument uses unnamed type}}1039 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}1040 X<const NoNameForLinkagePtr> x3;1041 // cxx98-error@-1 {{template argument uses unnamed type}}1042 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}1043 NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>();1044 // cxx98-error@-1 {{template argument uses unnamed type}}1045 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}1046 // cxx98-note@-3 {{while substituting explicitly-specified template arguments}}1047 NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>();1048 // cxx98-error@-1 {{template argument uses unnamed type}}1049 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}1050 // cxx98-note@-3 {{while substituting explicitly-specified template arguments}}1051 int n1 = take(noNameForLinkagePtr);1052 // cxx98-error@-1 {{template argument uses unnamed type}}1053 // cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}1054 // cxx98-note@-3 {{while substituting deduced template arguments}}1055 1056 X<Danger> x4;1057 1058 void f() {1059 struct NoLinkage {};1060 X<NoLinkage> a;1061 // cxx98-error@-1 {{template argument uses local type }}1062 X<const NoLinkage> b;1063 // cxx98-error@-1 {{template argument uses local type }}1064 get<NoLinkage>();1065 // cxx98-error@-1 {{template argument uses local type }}1066 // cxx98-note@-2 {{while substituting explicitly-specified template arguments}}1067 get<const NoLinkage>();1068 // cxx98-error@-1 {{template argument uses local type }}1069 // cxx98-note@-2 {{while substituting explicitly-specified template arguments}}1070 X<void (*)(NoLinkage A::*)> c;1071 // cxx98-error@-1 {{template argument uses local type }}1072 X<int NoLinkage::*> d;1073 // cxx98-error@-1 {{template argument uses local type }}1074 }1075} // namespace cwg621076 1077namespace cwg63 { // cwg63: 2.71078 template<typename T> struct S { typename T::error e; };1079 extern S<int> *p;1080 void *q = p;1081} // namespace cwg631082 1083namespace cwg64 { // cwg64: 2.71084 template<class T> void f(T);1085 template<class T> void f(T*);1086 template<> void f(int*);1087 template<> void f<int>(int*);1088 template<> void f(int);1089} // namespace cwg641090 1091// cwg65: na1092 1093namespace cwg66 { // cwg66: no1094 namespace X {1095 int f(int n); // #cwg66-f-first1096 }1097 using X::f;1098 namespace X {1099 int f(int n = 0);1100 int f(int, int);1101 }1102 // FIXME: The first two calls here should be accepted.1103 int a = f();1104 // expected-error@-1 {{no matching function for call to 'f'}}1105 // expected-note@#cwg66-f-first {{candidate function not viable: requires single argument 'n', but no arguments were provided}}1106 int b = f(1);1107 int c = f(1, 2);1108 // expected-error@-1 {{no matching function for call to 'f'}}1109 // expected-note@#cwg66-f-first {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}1110} // namespace cwg661111 1112// cwg67: na1113 1114namespace cwg68 { // cwg68: 2.81115 template<typename T> struct X {};1116 struct ::cwg68::X<int> x1;1117 struct ::cwg68::template X<int> x2;1118 // cxx98-error@-1 {{'template' keyword outside of a template}}1119 struct Y {1120 friend struct X<int>;1121 friend struct ::cwg68::X<char>;1122 friend struct ::cwg68::template X<double>;1123 // cxx98-error@-1 {{'template' keyword outside of a template}}1124 };1125 template<typename>1126 struct Z {1127 friend struct ::cwg68::template X<double>;1128 friend typename ::cwg68::X<double>;1129 // cxx98-error@-1 {{unelaborated friend declaration is a C++11 extension; specify 'struct' to befriend 'typename ::cwg68::X<double>'}}1130 };1131} // namespace cwg681132 1133namespace cwg69 { // cwg69: 91134 template<typename T> static void f() {} // #cwg69-f1135 // FIXME: Should we warn here?1136 inline void g() { f<int>(); }1137 extern template void f<char>();1138 // cxx98-error@-1 {{extern templates are a C++11 extension}}1139 // expected-error@-2 {{explicit instantiation declaration of 'f' with internal linkage}}1140 template<void(*)()> struct Q {};1141 Q<&f<int> > q;1142 // cxx98-error@-1 {{non-type template argument referring to function 'f<int>' with internal linkage is a C++11 extension}}1143 // cxx98-note@#cwg69-f {{non-type template argument refers to function here}}1144} // namespace cwg691145 1146namespace cwg70 { // cwg70: 2.71147 template<int> struct A {};1148 template<int I, int J> int f(int (&)[I + J], A<I>, A<J>);1149 int arr[7];1150 int k = f(arr, A<3>(), A<4>());1151} // namespace cwg701152 1153// cwg71: na1154// cwg72: dup 691155 1156namespace cwg73 { // cwg73: sup 16521157#if __cplusplus >= 201103L1158 int a, b;1159 static_assert(&a + 1 != &b, "");1160 // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}1161 // since-cxx11-note@-2 {{comparison against pointer '&a + 1' that points past the end of a complete object has unspecified value}}1162#endif1163} // namespace cwg731164 1165namespace cwg74 { // cwg74: 2.71166 enum E { k = 5 };1167 int (*p)[k] = new int[k][k];1168} // namespace cwg741169 1170namespace cwg75 { // cwg75: 2.71171 struct S {1172 static int n = 0;1173 // expected-error@-1 {{non-const static data member must be initialized out of line}}1174 };1175} // namespace cwg751176 1177namespace cwg76 { // cwg76: 2.71178 const volatile int n = 1;1179 static_assert(n, "");1180 // expected-error@-1 {{static assertion expression is not an integral constant expression}}1181 // expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}}1182} // namespace cwg761183 1184namespace cwg77 { // cwg77: 2.71185 struct A {1186 struct B {};1187 friend struct B;1188 };1189} // namespace cwg771190 1191namespace cwg78 { // cwg78: sup ????1192 // Under CWG78, this is valid, because 'k' has static storage duration, so is1193 // zero-initialized.1194 const int k;1195 // expected-error@-1 {{default initialization of an object of const type 'const int'}}1196} // namespace cwg781197 1198// cwg79: na1199 1200namespace cwg80 { // cwg80: 2.91201 struct A {1202 int A;1203 };1204 struct B {1205 static int B;1206 // expected-error@-1 {{member 'B' has the same name as its class}}1207 };1208 struct C {1209 int C;1210 // expected-error@-1 {{member 'C' has the same name as its class}}1211 C();1212 };1213 struct D {1214 D();1215 int D;1216 // expected-error@-1 {{member 'D' has the same name as its class}}1217 };1218} // namespace cwg801219 1220// cwg81: na1221// cwg82: dup 481222 1223namespace cwg83 { // cwg83: 2.71224 int &f(const char*);1225 char &f(char *);1226 int &k = f("foo");1227} // namespace cwg831228 1229namespace cwg84 { // cwg84: 2.71230 struct B;1231 struct A { operator B() const; };1232 struct C {};1233 struct B {1234 B(B&); // #cwg84-copy-ctor1235 B(C); // #cwg84-ctor-from-C1236 operator C() const;1237 };1238 A a;1239 // Cannot use B(C) / operator C() pair to construct the B from the B temporary1240 // here. In C++17, we initialize the B object directly using 'A::operator B()'.1241 B b = a;1242 // cxx98-14-error@-1 {{no viable constructor copying variable of type 'B'}}1243 // cxx98-14-note@#cwg84-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}1244 // cxx98-14-note@#cwg84-ctor-from-C {{candidate constructor not viable: no known conversion from 'B' to 'C' for 1st argument}}1245} // namespace cwg841246 1247namespace cwg85 { // cwg85: 3.41248 struct A {1249 struct B;1250 struct B {}; // #cwg85-B-def1251 struct B;1252 // expected-error@-1 {{class member cannot be redeclared}}1253 // expected-note@#cwg85-B-def {{previous declaration is here}}1254 1255 union U;1256 union U {}; // #cwg85-U-def1257 union U;1258 // expected-error@-1 {{class member cannot be redeclared}}1259 // expected-note@#cwg85-U-def {{previous declaration is here}}1260 1261#if __cplusplus >= 201103L1262 enum E1 : int;1263 enum E1 : int { e1 }; // #cwg85-E1-def1264 enum E1 : int;1265 // since-cxx11-error@-1 {{class member cannot be redeclared}}1266 // since-cxx11-note@#cwg85-E1-def {{previous declaration is here}}1267 1268 enum class E2;1269 enum class E2 { e2 }; // #cwg85-E2-def1270 enum class E2;1271 // since-cxx11-error@-1 {{class member cannot be redeclared}}1272 // since-cxx11-note@#cwg85-E2-def {{previous declaration is here}}1273#endif1274 };1275 1276 template <typename T>1277 struct C {1278 struct B {}; // #cwg85-C-B-def1279 struct B;1280 // expected-error@-1 {{class member cannot be redeclared}}1281 // expected-note@#cwg85-C-B-def {{previous declaration is here}}1282 };1283} // namespace cwg851284 1285// cwg86: dup 4461286 1287namespace cwg87 { // cwg87: no1288 // FIXME: Superseded by cwg19751289 template<typename T> struct X {};1290 // FIXME: This is invalid.1291 X<void() throw()> x;1292 // This is valid under cwg87 but not under cwg1975.1293 X<void(void() throw())> y;1294} // namespace cwg871295 1296namespace cwg88 { // cwg88: 2.81297 template<typename T> struct S {1298 static const int a = 1; // #cwg88-a1299 static const int b;1300 };1301 template<> const int S<int>::a = 4;1302 // expected-error@-1 {{static data member 'a' already has an initializer}}1303 // expected-note@#cwg88-a {{previous initialization is here}}1304 template<> const int S<int>::b = 4;1305} // namespace cwg881306 1307// cwg89: na1308 1309namespace cwg90 { // cwg90: 2.71310 struct A {1311 template<typename T> friend void cwg90_f(T);1312 };1313 struct B : A {1314 template<typename T> friend void cwg90_g(T);1315 struct C {};1316 union D {};1317 };1318 struct E : B {};1319 struct F : B::C {};1320 1321 void test() {1322 cwg90_f(A());1323 cwg90_f(B());1324 cwg90_f(B::C());1325 // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}1326 cwg90_f(B::D());1327 // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}1328 cwg90_f(E());1329 cwg90_f(F());1330 // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}1331 1332 cwg90_g(A());1333 // expected-error@-1 {{use of undeclared identifier 'cwg90_g'}}1334 cwg90_g(B());1335 cwg90_g(B::C());1336 cwg90_g(B::D());1337 cwg90_g(E());1338 cwg90_g(F());1339 // expected-error@-1 {{use of undeclared identifier 'cwg90_g'}}1340 }1341} // namespace cwg901342 1343namespace cwg91 { // cwg91: 2.71344 union U { friend int f(U); };1345 int k = f(U());1346} // namespace cwg911347 1348namespace cwg92 { // cwg92: 4 c++171349 void f() throw(int, float);1350 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}1351 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}1352 void (*p)() throw(int) = &f; // #cwg92-p1353 // since-cxx17-error@#cwg92-p {{ISO C++17 does not allow dynamic exception specifications}}1354 // since-cxx17-note@#cwg92-p {{use 'noexcept(false)' instead}}1355 // cxx98-14-error@#cwg92-p {{target exception specification is not superset of source}}1356 // since-cxx17-warning@#cwg92-p {{target exception specification is not superset of source}}1357 void (*q)() throw(int);1358 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}1359 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}1360 void (**pp)() throw() = &q;1361 // cxx98-14-error@-1 {{exception specifications are not allowed beyond a single level of indirection}}1362 // since-cxx17-error@-2 {{cannot initialize a variable of type 'void (**)() throw()' with an rvalue of type 'void (**)() throw(int)'}}1363 1364 void g(void() throw()); // #cwg92-g1365 // cxx98-14-warning@-1 {{mangled name of 'g' will change in C++17 due to non-throwing exception specification in function signature}}1366 void h() throw() {1367 g(f);1368 // cxx98-14-error@-1 {{target exception specification is not superset of source}}1369 // since-cxx17-error@-2 {{no matching function for call to 'g'}}1370 // since-cxx17-note@#cwg92-g {{candidate function not viable: no known conversion from 'void () throw(int, float)' to 'void (*)() throw()' for 1st argument}}1371 g(q);1372 // cxx98-14-error@-1 {{target exception specification is not superset of source}}1373 // since-cxx17-error@-2 {{no matching function for call to 'g'}}1374 // since-cxx17-note@#cwg92-g {{candidate function not viable: no known conversion from 'void (*)() throw(int)' to 'void (*)() throw()' for 1st argument}}1375 }1376 1377 // Prior to C++17, this is OK because the exception specification is not1378 // considered in this context. In C++17, we *do* perform an implicit1379 // conversion (which performs initialization), and the exception specification1380 // is part of the type of the parameter, so this is invalid.1381 template<void() throw()> struct X {}; // since-cxx17-note {{template parameter is declared here}}1382 X<&f> xp;1383 // since-cxx17-error@-1 {{value of type 'void (*)() throw(int, float)' is not implicitly convertible to 'void (*)() throw()'}}1384 1385 template<void() throw(int)> struct Y {};1386 // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}1387 // since-cxx17-note@-2 {{use 'noexcept(false)' instead}}1388 Y<&h> yp; // ok1389} // namespace cwg921390 1391// cwg93: na1392 1393namespace cwg94 { // cwg94: 2.71394 struct A { static const int n = 5; };1395 int arr[A::n];1396} // namespace cwg941397 1398namespace cwg95 { // cwg95: 3.31399 struct A;1400 struct B;1401 namespace N {1402 class C {1403 friend struct A;1404 friend struct B;1405 static void f(); // #cwg95-C-f1406 };1407 struct A *p; // cwg95::A, not cwg95::N::A.1408 }1409 A *q = N::p; // ok, same type1410 struct B { void f() { N::C::f(); } };1411 // expected-error@-1 {{'f' is a private member of 'cwg95::N::C'}}1412 // expected-note@#cwg95-C-f {{implicitly declared private here}}1413} // namespace cwg951414 1415namespace cwg96 { // cwg96: sup P17871416 struct A {1417 void f(int);1418 template<typename T> int f(T);1419 template<typename T> struct S {};1420 } a;1421 template<template<typename> class X> struct B {};1422 1423 template<typename T>1424 void test() {1425 int k1 = a.template f<int>(0);1426 // FIXME: This is ill-formed, because 'f' is not a template-id and does not1427 // name a class template.1428 // FIXME: What about alias templates?1429 int k2 = a.template f(1);1430 // expected-error@-1 {{a template argument list is expected after a name prefixed by the template keyword}}1431 A::template S<int> s;1432 B<A::template S> b;1433 }1434} // namespace cwg961435 1436namespace cwg97 { // cwg97: 2.71437 struct A {1438 static const int a = false;1439 static const int b = !a;1440 };1441} // namespace cwg971442 1443namespace cwg98 { // cwg98: 2.71444 void test(int n) {1445 switch (n) {1446 try { // #cwg98-try1447 case 0:1448 // expected-error@-1 {{cannot jump from switch statement to this case label}}1449 // expected-note@#cwg98-try {{jump bypasses initialization of try block}}1450 x:1451 throw n;1452 } catch (...) { // #cwg98-catch1453 case 1:1454 // expected-error@-1 {{cannot jump from switch statement to this case label}}1455 // expected-note@#cwg98-catch {{jump bypasses initialization of catch block}}1456 y:1457 throw n;1458 }1459 case 2:1460 goto x;1461 // expected-error@-1 {{cannot jump from this goto statement to its label}}1462 // expected-note@#cwg98-try {{jump bypasses initialization of try block}}1463 case 3:1464 goto y;1465 // expected-error@-1 {{cannot jump from this goto statement to its label}}1466 // expected-note@#cwg98-catch {{jump bypasses initialization of catch block}}1467 }1468 }1469} // namespace cwg981470 1471namespace cwg99 { // cwg99: sup 2141472 template<typename T> void f(T&);1473 template<typename T> int &f(const T&);1474 const int n = 0;1475 int &r = f(n);1476} // namespace cwg991477