1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -Wno-bind-to-temporary-copy 2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple 3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple 4 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple 5 6 namespace dr1 { // dr1: no 7 namespace X { extern "C" void dr1_f(int a = 1); } 8 namespace Y { extern "C" void dr1_f(int a = 1); } 9 using X::dr1_f; using Y::dr1_f; g()10 void g() { 11 dr1_f(0); 12 // FIXME: This should be rejected, due to the ambiguous default argument. 13 dr1_f(); 14 } 15 namespace X { 16 using Y::dr1_f; h()17 void h() { 18 dr1_f(0); 19 // FIXME: This should be rejected, due to the ambiguous default argument. 20 dr1_f(); 21 } 22 } 23 24 namespace X { 25 void z(int); 26 } z(int=1)27 void X::z(int = 1) {} // expected-note {{previous}} 28 namespace X { 29 void z(int = 1); // expected-error {{redefinition of default argument}} 30 } 31 32 void i(int = 1); j()33 void j() { 34 void i(int = 1); 35 using dr1::i; 36 i(0); 37 // FIXME: This should be rejected, due to the ambiguous default argument. 38 i(); 39 } k()40 void k() { 41 using dr1::i; 42 void i(int = 1); 43 i(0); 44 // FIXME: This should be rejected, due to the ambiguous default argument. 45 i(); 46 } 47 } 48 49 namespace dr3 { // dr3: yes 50 template<typename T> struct A {}; f(T)51 template<typename T> void f(T) { A<T> a; } // expected-note {{implicit instantiation}} 52 template void f(int); 53 template<> struct A<int> {}; // expected-error {{explicit specialization of 'dr3::A<int>' after instantiation}} 54 } 55 56 namespace dr4 { // dr4: yes 57 extern "C" { dr4_f(int)58 static void dr4_f(int) {} dr4_f(float)59 static void dr4_f(float) {} dr4_g(int)60 void dr4_g(int) {} // expected-note {{previous}} dr4_g(float)61 void dr4_g(float) {} // expected-error {{conflicting types}} 62 } 63 } 64 65 namespace dr5 { // dr5: yes 66 struct A {} a; 67 struct B { 68 B(const A&); 69 B(const B&); 70 }; 71 const volatile B b = a; 72 73 struct C { C(C&); }; 74 struct D : C {}; 75 struct E { operator D&(); } e; 76 const C c = e; 77 } 78 79 namespace dr7 { // dr7: yes 80 class A { public: ~A(); }; 81 class B : virtual private A {}; // expected-note 2 {{declared private here}} 82 class C : public B {} c; // expected-error 2 {{inherited virtual base class 'dr7::A' has private destructor}} \ 83 // expected-note {{implicit default constructor for 'dr7::C' first required here}} \ 84 // expected-note {{implicit destructor for 'dr7::C' first required here}} 85 class VeryDerivedC : public B, virtual public A {} vdc; 86 87 class X { ~X(); }; // expected-note {{here}} ~Y()88 class Y : X { ~Y() {} }; // expected-error {{private destructor}} 89 90 namespace PR16370 { // This regressed the first time DR7 was fixed. 91 struct S1 { virtual ~S1(); }; 92 struct S2 : S1 {}; 93 struct S3 : S2 {}; 94 struct S4 : virtual S2 {}; 95 struct S5 : S3, S4 { 96 S5(); 97 ~S5(); 98 }; S5()99 S5::S5() {} 100 } 101 } 102 103 namespace dr8 { // dr8: dup 45 104 class A { 105 struct U; 106 static const int k = 5; 107 void f(); 108 template<typename, int, void (A::*)()> struct T; 109 110 T<U, k, &A::f> *g(); 111 }; g()112 A::T<A::U, A::k, &A::f> *A::g() { return 0; } 113 } 114 115 namespace dr9 { // dr9: yes 116 struct B { 117 protected: 118 int m; // expected-note {{here}} 119 friend int R1(); 120 }; 121 struct N : protected B { // expected-note {{protected}} 122 friend int R2(); 123 } n; R1()124 int R1() { return n.m; } // expected-error {{protected member}} R2()125 int R2() { return n.m; } 126 } 127 128 namespace dr10 { // dr10: dup 45 129 class A { 130 struct B { 131 A::B *p; 132 }; 133 }; 134 } 135 136 namespace dr11 { // dr11: yes 137 template<typename T> struct A : T { 138 using typename T::U; 139 U u; 140 }; 141 template<typename T> struct B : T { 142 using T::V; 143 V v; // expected-error {{unknown type name}} 144 }; 145 struct X { typedef int U; }; 146 A<X> ax; 147 } 148 149 namespace dr12 { // dr12: sup 239 150 enum E { e }; 151 E &f(E, E = e); g()152 void g() { 153 int &f(int, E = e); 154 // Under DR12, these call two different functions. 155 // Under DR239, they call the same function. 156 int &b = f(e); 157 int &c = f(1); 158 } 159 } 160 161 namespace dr13 { // dr13: no 162 extern "C" void f(int); 163 void g(char); 164 165 template<typename T> struct A { 166 A(void (*fp)(T)); 167 }; 168 template<typename T> int h(void (T)); 169 170 A<int> a1(f); // FIXME: We should reject this. 171 A<char> a2(g); 172 int a3 = h(f); // FIXME: We should reject this. 173 int a4 = h(g); 174 } 175 176 namespace dr14 { // dr14: yes 177 namespace X { extern "C" int dr14_f(); } 178 namespace Y { extern "C" int dr14_f(); } 179 using namespace X; 180 using namespace Y; 181 int k = dr14_f(); 182 183 class C { 184 int k; 185 friend int Y::dr14_f(); 186 } c; 187 namespace Z { dr14_f()188 extern "C" int dr14_f() { return c.k; } 189 } 190 191 namespace X { typedef int T; typedef int U; } // expected-note {{candidate}} 192 namespace Y { typedef int T; typedef long U; } // expected-note {{candidate}} 193 T t; // ok, same type both times 194 U u; // expected-error {{ambiguous}} 195 } 196 197 namespace dr15 { // dr15: yes 198 template<typename T> void f(int); // expected-note {{previous}} 199 template<typename T> void f(int = 0); // expected-error {{default arguments cannot be added}} 200 } 201 202 namespace dr16 { // dr16: yes 203 class A { // expected-note {{here}} 204 void f(); // expected-note {{here}} 205 friend class C; 206 }; 207 class B : A {}; // expected-note 3{{here}} 208 class C : B { g()209 void g() { 210 f(); // expected-error {{private member}} 211 A::f(); // expected-error {{private member}} expected-error {{private base}} 212 } 213 }; 214 } 215 216 namespace dr17 { // dr17: yes 217 class A { 218 int n; 219 int f(); 220 struct C; 221 }; 222 struct B : A {} b; f()223 int A::f() { return b.n; } 224 struct A::C : A { gdr17::A::C225 int g() { return n; } 226 }; 227 } 228 229 // dr18: sup 577 230 231 namespace dr19 { // dr19: yes 232 struct A { 233 int n; // expected-note {{here}} 234 }; 235 struct B : protected A { // expected-note {{here}} 236 }; 237 struct C : B {} c; 238 struct D : B { get1dr19::D239 int get1() { return c.n; } // expected-error {{protected member}} get2dr19::D240 int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here 241 }; 242 } 243 244 namespace dr20 { // dr20: yes 245 class X { 246 public: 247 X(); 248 private: 249 X(const X&); // expected-note {{here}} 250 }; 251 X &f(); 252 X x = f(); // expected-error {{private}} 253 } 254 255 namespace dr21 { // dr21: yes 256 template<typename T> struct A; 257 struct X { 258 template<typename T = int> friend struct A; // expected-error {{default template argument not permitted on a friend template}} 259 template<typename T = int> friend struct B; // expected-error {{default template argument not permitted on a friend template}} 260 }; 261 } 262 263 namespace dr22 { // dr22: sup 481 264 template<typename dr22_T = dr22_T> struct X; // expected-error {{unknown type name 'dr22_T'}} 265 typedef int T; 266 template<typename T = T> struct Y; 267 } 268 269 namespace dr23 { // dr23: yes 270 template<typename T> void f(T, T); // expected-note {{candidate}} 271 template<typename T> void f(T, int); // expected-note {{candidate}} g()272 void g() { f(0, 0); } // expected-error {{ambiguous}} 273 } 274 275 // dr24: na 276 277 namespace dr25 { // dr25: yes 278 struct A { 279 void f() throw(int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}} 280 }; 281 void (A::*f)() throw (int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}} 282 void (A::*g)() throw () = f; 283 #if __cplusplus <= 201402L 284 // expected-error@-2 {{is not superset of source}} 285 #else 286 // expected-error@-4 {{different exception specifications}} 287 #endif 288 void (A::*g2)() throw () = 0; 289 void (A::*h)() throw (int, char) = f; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}} 290 void (A::*i)() throw () = &A::f; 291 #if __cplusplus <= 201402L 292 // expected-error@-2 {{is not superset of source}} 293 #else 294 // expected-error@-4 {{different exception specifications}} 295 #endif 296 void (A::*i2)() throw () = 0; 297 void (A::*j)() throw (int, char) = &A::f; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}} x()298 void x() { 299 g2 = f; 300 #if __cplusplus <= 201402L 301 // expected-error@-2 {{is not superset of source}} 302 #else 303 // expected-error@-4 {{different exception specifications}} 304 #endif 305 h = f; 306 i2 = &A::f; 307 #if __cplusplus <= 201402L 308 // expected-error@-2 {{is not superset of source}} 309 #else 310 // expected-error@-4 {{different exception specifications}} 311 #endif 312 j = &A::f; 313 } 314 } 315 316 namespace dr26 { // dr26: yes 317 struct A { A(A, const A & = A()); }; // expected-error {{must pass its first argument by reference}} 318 struct B { 319 B(); 320 // FIXME: In C++98, we diagnose this twice. 321 B(const B &, B = B()); 322 #if __cplusplus <= 201402L 323 // expected-error@-2 1+{{recursive evaluation of default argument}} expected-note@-2 1+{{used here}} 324 #endif 325 }; 326 struct C { 327 static C &f(); 328 C(const C &, C = f()); // expected-error {{recursive evaluation of default argument}} expected-note {{used here}} 329 }; 330 } 331 332 namespace dr27 { // dr27: yes 333 enum E { e } n; 334 E &m = true ? n : n; 335 } 336 337 // dr28: na lib 338 339 namespace dr29 { // dr29: 3.4 340 void dr29_f0(); // expected-note {{here}} g0()341 void g0() { void dr29_f0(); } g0_cxx()342 extern "C++" void g0_cxx() { void dr29_f0(); } g0_c()343 extern "C" void g0_c() { void dr29_f0(); } // expected-error {{different language linkage}} 344 345 extern "C" void dr29_f1(); // expected-note {{here}} g1()346 void g1() { void dr29_f1(); } g1_c()347 extern "C" void g1_c() { void dr29_f1(); } g1_cxx()348 extern "C++" void g1_cxx() { void dr29_f1(); } // expected-error {{different language linkage}} 349 g2()350 void g2() { void dr29_f2(); } // expected-note {{here}} 351 extern "C" void dr29_f2(); // expected-error {{different language linkage}} 352 g3()353 extern "C" void g3() { void dr29_f3(); } // expected-note {{here}} 354 extern "C++" void dr29_f3(); // expected-error {{different language linkage}} 355 g4()356 extern "C++" void g4() { void dr29_f4(); } // expected-note {{here}} 357 extern "C" void dr29_f4(); // expected-error {{different language linkage}} 358 359 extern "C" void g5(); 360 extern "C++" void dr29_f5(); g5()361 void g5() { 362 void dr29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here. 363 } 364 365 extern "C++" void g6(); 366 extern "C" void dr29_f6(); g6()367 void g6() { 368 void dr29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here. 369 } 370 371 extern "C" void g7(); 372 extern "C++" void dr29_f7(); // expected-note {{here}} g7()373 extern "C" void g7() { 374 void dr29_f7(); // expected-error {{different language linkage}} 375 } 376 377 extern "C++" void g8(); 378 extern "C" void dr29_f8(); // expected-note {{here}} g8()379 extern "C++" void g8() { 380 void dr29_f8(); // expected-error {{different language linkage}} 381 } 382 } 383 384 namespace dr30 { // dr30: sup 468 c++11 385 struct A { 386 template<int> static int f(); 387 } a, *p = &a; 388 int x = A::template f<0>(); 389 int y = a.template f<0>(); 390 int z = p->template f<0>(); 391 #if __cplusplus < 201103L 392 // FIXME: It's not clear whether DR468 applies to C++98 too. 393 // expected-error@-5 {{'template' keyword outside of a template}} 394 // expected-error@-5 {{'template' keyword outside of a template}} 395 // expected-error@-5 {{'template' keyword outside of a template}} 396 #endif 397 } 398 399 namespace dr31 { // dr31: yes 400 class X { 401 private: 402 void operator delete(void*); // expected-note {{here}} 403 }; 404 // We would call X::operator delete if X() threw (even though it can't, 405 // and even though we allocated the X using ::operator delete). 406 X *p = new X; // expected-error {{private}} 407 } 408 409 // dr32: na 410 411 namespace dr33 { // dr33: yes 412 namespace X { struct S; void f(void (*)(S)); } // expected-note {{candidate}} 413 namespace Y { struct T; void f(void (*)(T)); } // expected-note {{candidate}} 414 void g(X::S); 415 template<typename Z> Z g(Y::T); h()416 void h() { f(&g); } // expected-error {{ambiguous}} 417 418 template<typename T> void t(X::S); 419 template<typename T, typename U = void> void u(X::S); // expected-error 0-1{{default template argument}} templ()420 void templ() { f(t<int>); f(u<int>); } 421 422 // Even though v<int> cannot select the first overload, ADL considers it 423 // and adds namespace Z to the set of associated namespaces, and then picks 424 // Z::f even though that function has nothing to do with any associated type. 425 namespace Z { struct Q; void f(void(*)()); } 426 template<int> Z::Q v(); 427 template<typename> void v(); unrelated_templ()428 void unrelated_templ() { f(v<int>); } 429 430 namespace dependent { 431 struct X {}; 432 template<class T> struct Y { operator +(X,void (*)(Y))433 friend int operator+(X, void(*)(Y)) {} 434 }; 435 436 template<typename T> void f(Y<T>); 437 int use = X() + f<int>; // expected-error {{invalid operands}} 438 } 439 440 namespace member { 441 struct Q {}; 442 struct Y { friend int operator+(Q, Y (*)()); }; 443 struct X { template<typename> static Y f(); }; 444 int m = Q() + X().f<int>; // ok 445 int n = Q() + (&(X().f<int>)); // ok 446 } 447 } 448 449 // dr34: na 450 // dr35: dup 178 451 // dr37: sup 475 452 453 namespace dr38 { // dr38: yes 454 template<typename T> struct X {}; operator +(X<T> a,X<T> b)455 template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; } 456 template X<int> operator+<int>(X<int>, X<int>); 457 } 458 459 namespace dr39 { // dr39: no 460 namespace example1 { 461 struct A { int &f(int); }; 462 struct B : A { 463 using A::f; 464 float &f(float); 465 } b; 466 int &r = b.f(0); 467 } 468 469 namespace example2 { 470 struct A { 471 int &x(int); // expected-note {{found}} 472 static int &y(int); // expected-note {{found}} 473 }; 474 struct V { 475 int &z(int); 476 }; 477 struct B : A, virtual V { 478 using A::x; // expected-note {{found}} 479 float &x(float); 480 using A::y; // expected-note {{found}} 481 static float &y(float); 482 using V::z; 483 float &z(float); 484 }; 485 struct C : A, B, virtual V {} c; // expected-warning {{direct base 'dr39::example2::A' is inaccessible due to ambiguity:\n struct dr39::example2::C -> struct dr39::example2::A\n struct dr39::example2::C -> struct dr39::example2::B -> struct dr39::example2::A}} 486 int &x = c.x(0); // expected-error {{found in multiple base classes}} 487 // FIXME: This is valid, because we find the same static data member either way. 488 int &y = c.y(0); // expected-error {{found in multiple base classes}} 489 int &z = c.z(0); 490 } 491 492 namespace example3 { 493 struct A { static int f(); }; 494 struct B : virtual A { using A::f; }; 495 struct C : virtual A { using A::f; }; 496 struct D : B, C {} d; 497 int k = d.f(); 498 } 499 500 namespace example4 { 501 struct A { int n; }; // expected-note {{found}} 502 struct B : A {}; 503 struct C : A {}; fdr39::example4::D504 struct D : B, C { int f() { return n; } }; // expected-error {{found in multiple base-class}} 505 } 506 507 namespace PR5916 { 508 // FIXME: This is valid. 509 struct A { int n; }; // expected-note +{{found}} 510 struct B : A {}; 511 struct C : A {}; 512 struct D : B, C {}; 513 int k = sizeof(D::n); // expected-error {{found in multiple base}} expected-error {{unknown type name}} 514 #if __cplusplus >= 201103L 515 decltype(D::n) n; // expected-error {{found in multiple base}} 516 #endif 517 } 518 } 519 520 // dr40: na 521 522 namespace dr41 { // dr41: yes 523 struct S f(S); 524 } 525 526 namespace dr42 { // dr42: yes 527 struct A { static const int k = 0; }; 528 struct B : A { static const int k = A::k; }; 529 } 530 531 // dr43: na 532 533 namespace dr44 { // dr44: sup 727 534 struct A { 535 template<int> void f(); 536 template<> void f<0>(); 537 }; 538 } 539 540 namespace dr45 { // dr45: yes 541 class A { 542 class B {}; 543 class C : B {}; 544 C c; 545 }; 546 } 547 548 namespace dr46 { // dr46: yes 549 template<typename> struct A { template<typename> struct B {}; }; 550 template template struct A<int>::B<int>; // expected-error {{expected unqualified-id}} 551 } 552 553 namespace dr47 { // dr47: sup 329 554 template<typename T> struct A { f()555 friend void f() { T t; } // expected-error {{redefinition}} expected-note {{previous}} 556 }; 557 A<int> a; 558 A<float> b; // expected-note {{instantiation of}} 559 560 void f(); g()561 void g() { f(); } 562 } 563 564 namespace dr48 { // dr48: yes 565 namespace { 566 struct S { 567 static const int m = 0; 568 static const int n = 0; 569 static const int o = 0; 570 }; 571 } 572 int a = S::m; 573 // FIXME: We should produce a 'has internal linkage but is not defined' 574 // diagnostic for 'S::n'. 575 const int &b = S::n; 576 const int S::o; 577 const int &c = S::o; 578 } 579 580 namespace dr49 { // dr49: yes 581 template<int*> struct A {}; // expected-note 0-2{{here}} 582 int k; 583 #if __has_feature(cxx_constexpr) 584 constexpr 585 #endif 586 int *const p = &k; // expected-note 0-2{{here}} 587 A<&k> a; 588 A<p> b; 589 #if __cplusplus <= 201402L 590 // expected-error@-2 {{must have its address taken}} 591 #endif 592 #if __cplusplus < 201103L 593 // expected-error@-5 {{internal linkage}} 594 #endif 595 int *q = &k; 596 A<q> c; 597 #if __cplusplus < 201103L 598 // expected-error@-2 {{must have its address taken}} 599 #else 600 // expected-error@-4 {{constant expression}} 601 // expected-note@-5 {{read of non-constexpr}} 602 // expected-note@-7 {{declared here}} 603 #endif 604 } 605 606 namespace dr50 { // dr50: yes 607 struct X; // expected-note {{forward}} 608 extern X *p; 609 X *q = (X*)p; 610 X *r = static_cast<X*>(p); 611 X *s = const_cast<X*>(p); 612 X *t = reinterpret_cast<X*>(p); 613 X *u = dynamic_cast<X*>(p); // expected-error {{incomplete}} 614 } 615 616 namespace dr51 { // dr51: yes 617 struct A {}; 618 struct B : A {}; 619 struct S { 620 operator A&(); 621 operator B&(); 622 } s; 623 A &a = s; 624 } 625 626 namespace dr52 { // dr52: yes 627 struct A { int n; }; // expected-note {{here}} 628 struct B : private A {} b; // expected-note 2{{private}} 629 // FIXME: This first diagnostic is very strangely worded, and seems to be bogus. 630 int k = b.A::n; // expected-error {{'A' is a private member of 'dr52::A'}} 631 // expected-error@-1 {{cannot cast 'struct B' to its private base}} 632 } 633 634 namespace dr53 { // dr53: yes 635 int n = 0; 636 enum E { e } x = static_cast<E>(n); 637 } 638 639 namespace dr54 { // dr54: yes 640 struct A { int a; } a; 641 struct V { int v; } v; 642 struct B : private A, virtual V { int b; } b; // expected-note 6{{private here}} 643 644 A &sab = static_cast<A&>(b); // expected-error {{private base}} 645 A *spab = static_cast<A*>(&b); // expected-error {{private base}} 646 int A::*smab = static_cast<int A::*>(&B::b); // expected-error {{private base}} 647 B &sba = static_cast<B&>(a); // expected-error {{private base}} 648 B *spba = static_cast<B*>(&a); // expected-error {{private base}} 649 int B::*smba = static_cast<int B::*>(&A::a); // expected-error {{private base}} 650 651 V &svb = static_cast<V&>(b); 652 V *spvb = static_cast<V*>(&b); 653 int V::*smvb = static_cast<int V::*>(&B::b); // expected-error {{virtual base}} 654 B &sbv = static_cast<B&>(v); // expected-error {{virtual base}} 655 B *spbv = static_cast<B*>(&v); // expected-error {{virtual base}} 656 int B::*smbv = static_cast<int B::*>(&V::v); // expected-error {{virtual base}} 657 658 A &cab = (A&)(b); 659 A *cpab = (A*)(&b); 660 int A::*cmab = (int A::*)(&B::b); 661 B &cba = (B&)(a); 662 B *cpba = (B*)(&a); 663 int B::*cmba = (int B::*)(&A::a); 664 665 V &cvb = (V&)(b); 666 V *cpvb = (V*)(&b); 667 int V::*cmvb = (int V::*)(&B::b); // expected-error {{virtual base}} 668 B &cbv = (B&)(v); // expected-error {{virtual base}} 669 B *cpbv = (B*)(&v); // expected-error {{virtual base}} 670 int B::*cmbv = (int B::*)(&V::v); // expected-error {{virtual base}} 671 } 672 673 namespace dr55 { // dr55: yes 674 enum E { e = 5 }; 675 int test[(e + 1 == 6) ? 1 : -1]; 676 } 677 678 namespace dr56 { // dr56: yes 679 struct A { 680 typedef int T; // expected-note {{previous}} 681 typedef int T; // expected-error {{redefinition}} 682 }; 683 struct B { 684 struct X; 685 typedef X X; // expected-note {{previous}} 686 typedef X X; // expected-error {{redefinition}} 687 }; 688 } 689 690 namespace dr58 { // dr58: yes 691 // FIXME: Ideally, we should have a CodeGen test for this. 692 #if __cplusplus >= 201103L 693 enum E1 { E1_0 = 0, E1_1 = 1 }; 694 enum E2 { E2_0 = 0, E2_m1 = -1 }; 695 struct X { E1 e1 : 1; E2 e2 : 1; }; 696 static_assert(X{E1_1, E2_m1}.e1 == 1, ""); 697 static_assert(X{E1_1, E2_m1}.e2 == -1, ""); 698 #endif 699 } 700 701 namespace dr59 { // dr59: yes 702 template<typename T> struct convert_to { operator T() const; }; 703 struct A {}; // expected-note 5+{{candidate}} 704 struct B : A {}; // expected-note 0+{{candidate}} 705 706 A a1 = convert_to<A>(); 707 A a2 = convert_to<A&>(); 708 A a3 = convert_to<const A>(); 709 A a4 = convert_to<const volatile A>(); 710 #if __cplusplus <= 201402L 711 // expected-error@-2 {{no viable}} 712 #endif 713 A a5 = convert_to<const volatile A&>(); // expected-error {{no viable}} 714 715 B b1 = convert_to<B>(); 716 B b2 = convert_to<B&>(); 717 B b3 = convert_to<const B>(); 718 B b4 = convert_to<const volatile B>(); 719 #if __cplusplus <= 201402L 720 // expected-error@-2 {{no viable}} 721 #endif 722 B b5 = convert_to<const volatile B&>(); // expected-error {{no viable}} 723 724 A c1 = convert_to<B>(); 725 A c2 = convert_to<B&>(); 726 A c3 = convert_to<const B>(); 727 A c4 = convert_to<const volatile B>(); // expected-error {{no viable}} 728 A c5 = convert_to<const volatile B&>(); // expected-error {{no viable}} 729 730 int n1 = convert_to<int>(); 731 int n2 = convert_to<int&>(); 732 int n3 = convert_to<const int>(); 733 int n4 = convert_to<const volatile int>(); 734 int n5 = convert_to<const volatile int&>(); 735 } 736 737 namespace dr60 { // dr60: yes 738 void f(int &); 739 int &f(...); 740 const int k = 0; 741 int &n = f(k); 742 } 743 744 namespace dr61 { // dr61: yes 745 struct X { 746 static void f(); 747 } x; 748 struct Y { 749 static void f(); 750 static void f(int); 751 } y; 752 // This is (presumably) valid, because x.f does not refer to an overloaded 753 // function name. 754 void (*p)() = &x.f; 755 void (*q)() = &y.f; // expected-error {{cannot create a non-constant pointer to member function}} 756 void (*r)() = y.f; // expected-error {{cannot create a non-constant pointer to member function}} 757 } 758 759 namespace dr62 { // dr62: yes 760 struct A { 761 struct { int n; } b; 762 }; 763 template<typename T> struct X {}; get()764 template<typename T> T get() { return get<T>(); } take(T)765 template<typename T> int take(T) { return 0; } 766 767 X<A> x1; 768 A a = get<A>(); 769 770 typedef struct { } *NoNameForLinkagePtr; 771 #if __cplusplus < 201103L 772 // expected-note@-2 5{{here}} 773 #endif 774 NoNameForLinkagePtr noNameForLinkagePtr; 775 776 struct Danger { 777 NoNameForLinkagePtr p; 778 }; 779 780 X<NoNameForLinkagePtr> x2; 781 X<const NoNameForLinkagePtr> x3; 782 NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>(); 783 NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>(); 784 int n1 = take(noNameForLinkagePtr); 785 #if __cplusplus < 201103L 786 // expected-error@-6 {{uses unnamed type}} 787 // expected-error@-6 {{uses unnamed type}} 788 // expected-error@-6 {{uses unnamed type}} 789 // expected-error@-6 {{uses unnamed type}} 790 // expected-error@-6 {{uses unnamed type}} 791 #endif 792 793 X<Danger> x4; 794 f()795 void f() { 796 struct NoLinkage {}; 797 X<NoLinkage> a; 798 X<const NoLinkage> b; 799 get<NoLinkage>(); 800 get<const NoLinkage>(); 801 X<void (*)(NoLinkage A::*)> c; 802 X<int NoLinkage::*> d; 803 #if __cplusplus < 201103L 804 // expected-error@-7 {{uses local type}} 805 // expected-error@-7 {{uses local type}} 806 // expected-error@-7 {{uses local type}} 807 // expected-error@-7 {{uses local type}} 808 // expected-error@-7 {{uses local type}} 809 // expected-error@-7 {{uses local type}} 810 #endif 811 } 812 } 813 814 namespace dr63 { // dr63: yes 815 template<typename T> struct S { typename T::error e; }; 816 extern S<int> *p; 817 void *q = p; 818 } 819 820 namespace dr64 { // dr64: yes 821 template<class T> void f(T); 822 template<class T> void f(T*); 823 template<> void f(int*); 824 template<> void f<int>(int*); 825 template<> void f(int); 826 } 827 828 // dr65: na 829 830 namespace dr66 { // dr66: no 831 namespace X { 832 int f(int n); // expected-note 2{{candidate}} 833 } 834 using X::f; 835 namespace X { 836 int f(int n = 0); 837 int f(int, int); 838 } 839 // FIXME: The first two calls here should be accepted. 840 int a = f(); // expected-error {{no matching function}} 841 int b = f(1); 842 int c = f(1, 2); // expected-error {{no matching function}} 843 } 844 845 // dr67: na 846 847 namespace dr68 { // dr68: yes 848 template<typename T> struct X {}; 849 struct ::dr68::X<int> x1; 850 struct ::dr68::template X<int> x2; 851 #if __cplusplus < 201103L 852 // expected-error@-2 {{'template' keyword outside of a template}} 853 #endif 854 struct Y { 855 friend struct X<int>; 856 friend struct ::dr68::X<char>; 857 friend struct ::dr68::template X<double>; 858 #if __cplusplus < 201103L 859 // expected-error@-2 {{'template' keyword outside of a template}} 860 #endif 861 }; 862 template<typename> 863 struct Z { 864 friend struct ::dr68::template X<double>; 865 friend typename ::dr68::X<double>; 866 #if __cplusplus < 201103L 867 // expected-error@-2 {{C++11 extension}} 868 #endif 869 }; 870 } 871 872 namespace dr69 { // dr69: yes f()873 template<typename T> static void f() {} // #dr69-f 874 // FIXME: Should we warn here? g()875 inline void g() { f<int>(); } 876 extern template void f<char>(); // expected-error {{explicit instantiation declaration of 'f' with internal linkage}} 877 #if __cplusplus < 201103L 878 // expected-error@-2 {{C++11 extension}} 879 #endif 880 template<void(*)()> struct Q {}; 881 Q<&f<int> > q; 882 #if __cplusplus < 201103L 883 // expected-error@-2 {{internal linkage}} expected-note@#dr69-f {{here}} 884 #endif 885 } 886 887 namespace dr70 { // dr70: yes 888 template<int> struct A {}; 889 template<int I, int J> int f(int (&)[I + J], A<I>, A<J>); 890 int arr[7]; 891 int k = f(arr, A<3>(), A<4>()); 892 } 893 894 // dr71: na 895 // dr72: dup 69 896 897 #if __cplusplus >= 201103L 898 namespace dr73 { // dr73: no 899 // The resolution to dr73 is unworkable. Consider: 900 int a, b; 901 static_assert(&a + 1 != &b, ""); // expected-error {{not an integral constant expression}} 902 } 903 #endif 904 905 namespace dr74 { // dr74: yes 906 enum E { k = 5 }; 907 int (*p)[k] = new int[k][k]; 908 } 909 910 namespace dr75 { // dr75: yes 911 struct S { 912 static int n = 0; // expected-error {{non-const}} 913 }; 914 } 915 916 namespace dr76 { // dr76: yes 917 const volatile int n = 1; 918 int arr[n]; // expected-error +{{variable length array}} expected-note {{read of volatile}} 919 } 920 921 namespace dr77 { // dr77: yes 922 struct A { 923 struct B {}; 924 friend struct B; 925 }; 926 } 927 928 namespace dr78 { // dr78: sup ???? 929 // Under DR78, this is valid, because 'k' has static storage duration, so is 930 // zero-initialized. 931 const int k; // expected-error {{default initialization of an object of const}} 932 } 933 934 // dr79: na 935 936 namespace dr80 { // dr80: yes 937 struct A { 938 int A; 939 }; 940 struct B { 941 static int B; // expected-error {{same name as its class}} 942 }; 943 struct C { 944 int C; // expected-error {{same name as its class}} 945 C(); 946 }; 947 struct D { 948 D(); 949 int D; // expected-error {{same name as its class}} 950 }; 951 } 952 953 // dr81: na 954 // dr82: dup 48 955 956 namespace dr83 { // dr83: yes 957 int &f(const char*); 958 char &f(char *); 959 int &k = f("foo"); 960 } 961 962 namespace dr84 { // dr84: yes 963 struct B; 964 struct A { operator B() const; }; 965 struct C {}; 966 struct B { 967 B(B&); // expected-note 0-1{{candidate}} 968 B(C); // expected-note 0-1{{no known conversion from 'dr84::B' to 'dr84::C'}} 969 operator C() const; 970 }; 971 A a; 972 // Cannot use B(C) / operator C() pair to construct the B from the B temporary 973 // here. In C++17, we initialize the B object directly using 'A::operator B()'. 974 B b = a; 975 #if __cplusplus <= 201402L 976 // expected-error@-2 {{no viable}} 977 #endif 978 } 979 980 namespace dr85 { // dr85: yes 981 struct A { 982 struct B; 983 struct B {}; // expected-note{{previous declaration is here}} 984 struct B; // expected-error{{class member cannot be redeclared}} 985 986 union U; 987 union U {}; // expected-note{{previous declaration is here}} 988 union U; // expected-error{{class member cannot be redeclared}} 989 990 #if __cplusplus >= 201103L 991 enum E1 : int; 992 enum E1 : int { e1 }; // expected-note{{previous declaration is here}} 993 enum E1 : int; // expected-error{{class member cannot be redeclared}} 994 995 enum class E2; 996 enum class E2 { e2 }; // expected-note{{previous declaration is here}} 997 enum class E2; // expected-error{{class member cannot be redeclared}} 998 #endif 999 }; 1000 1001 template <typename T> 1002 struct C { 1003 struct B {}; // expected-note{{previous declaration is here}} 1004 struct B; // expected-error{{class member cannot be redeclared}} 1005 }; 1006 } 1007 1008 // dr86: dup 446 1009 1010 namespace dr87 { // dr87: no 1011 // FIXME: Superseded by dr1975 1012 template<typename T> struct X {}; 1013 // FIXME: This is invalid. 1014 X<void() throw()> x; 1015 // This is valid under dr87 but not under dr1975. 1016 X<void(void() throw())> y; 1017 } 1018 1019 namespace dr88 { // dr88: yes 1020 template<typename T> struct S { 1021 static const int a = 1; // expected-note {{previous}} 1022 static const int b; 1023 }; 1024 template<> const int S<int>::a = 4; // expected-error {{already has an initializer}} 1025 template<> const int S<int>::b = 4; 1026 } 1027 1028 // dr89: na 1029 1030 namespace dr90 { // dr90: yes 1031 struct A { 1032 template<typename T> friend void dr90_f(T); 1033 }; 1034 struct B : A { 1035 template<typename T> friend void dr90_g(T); 1036 struct C {}; 1037 union D {}; 1038 }; 1039 struct E : B {}; 1040 struct F : B::C {}; 1041 test()1042 void test() { 1043 dr90_f(A()); 1044 dr90_f(B()); 1045 dr90_f(B::C()); // expected-error {{undeclared identifier}} 1046 dr90_f(B::D()); // expected-error {{undeclared identifier}} 1047 dr90_f(E()); 1048 dr90_f(F()); // expected-error {{undeclared identifier}} 1049 1050 dr90_g(A()); // expected-error {{undeclared identifier}} 1051 dr90_g(B()); 1052 dr90_g(B::C()); 1053 dr90_g(B::D()); 1054 dr90_g(E()); 1055 dr90_g(F()); // expected-error {{undeclared identifier}} 1056 } 1057 } 1058 1059 namespace dr91 { // dr91: yes 1060 union U { friend int f(U); }; 1061 int k = f(U()); 1062 } 1063 1064 namespace dr92 { // dr92: 4 c++17 1065 void f() throw(int, float); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}} 1066 void (*p)() throw(int) = &f; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}} 1067 #if __cplusplus <= 201402L 1068 // expected-error@-2 {{target exception specification is not superset of source}} 1069 #else 1070 // expected-warning@-4 {{target exception specification is not superset of source}} 1071 #endif 1072 void (*q)() throw(int); // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}} 1073 void (**pp)() throw() = &q; 1074 #if __cplusplus <= 201402L 1075 // expected-error@-2 {{exception specifications are not allowed}} 1076 #else 1077 // expected-error@-4 {{cannot initialize}} 1078 #endif 1079 1080 void g(void() throw()); // expected-note 0-2 {{no known conversion}} expected-warning 0-1{{mangled name of 'g' will change in C++17}} h()1081 void h() throw() { 1082 g(f); // expected-error-re {{{{is not superset|no matching function}}}} 1083 g(q); // expected-error-re {{{{is not superset|no matching function}}}} 1084 } 1085 1086 // Prior to C++17, this is OK because the exception specification is not 1087 // considered in this context. In C++17, we *do* perform an implicit 1088 // conversion (which performs initialization), and the exception specification 1089 // is part of the type of the parameter, so this is invalid. 1090 template<void() throw()> struct X {}; 1091 X<&f> xp; 1092 #if __cplusplus > 201402L 1093 // expected-error@-2 {{not implicitly convertible}} 1094 #endif 1095 1096 template<void() throw(int)> struct Y {}; // expected-error 0-1{{ISO C++17 does not allow}} expected-note 0-1{{use 'noexcept}} 1097 Y<&h> yp; // ok 1098 } 1099 1100 // dr93: na 1101 1102 namespace dr94 { // dr94: yes 1103 struct A { static const int n = 5; }; 1104 int arr[A::n]; 1105 } 1106 1107 namespace dr95 { // dr95: yes 1108 struct A; 1109 struct B; 1110 namespace N { 1111 class C { 1112 friend struct A; 1113 friend struct B; 1114 static void f(); // expected-note {{here}} 1115 }; 1116 struct A *p; // dr95::A, not dr95::N::A. 1117 } 1118 A *q = N::p; // ok, same type fdr95::B1119 struct B { void f() { N::C::f(); } }; // expected-error {{private}} 1120 } 1121 1122 namespace dr96 { // dr96: no 1123 struct A { 1124 void f(int); 1125 template<typename T> int f(T); 1126 template<typename T> struct S {}; 1127 } a; 1128 template<template<typename> class X> struct B {}; 1129 1130 template<typename T> test()1131 void test() { 1132 int k1 = a.template f<int>(0); 1133 // FIXME: This is ill-formed, because 'f' is not a template-id and does not 1134 // name a class template. 1135 // FIXME: What about alias templates? 1136 int k2 = a.template f(1); 1137 A::template S<int> s; 1138 B<A::template S> b; 1139 } 1140 } 1141 1142 namespace dr97 { // dr97: yes 1143 struct A { 1144 static const int a = false; 1145 static const int b = !a; 1146 }; 1147 } 1148 1149 namespace dr98 { // dr98: yes test(int n)1150 void test(int n) { 1151 switch (n) { 1152 try { // expected-note 2{{bypasses}} 1153 case 0: // expected-error {{cannot jump}} 1154 x: 1155 throw n; 1156 } catch (...) { // expected-note 2{{bypasses}} 1157 case 1: // expected-error {{cannot jump}} 1158 y: 1159 throw n; 1160 } 1161 case 2: 1162 goto x; // expected-error {{cannot jump}} 1163 case 3: 1164 goto y; // expected-error {{cannot jump}} 1165 } 1166 } 1167 } 1168 1169 namespace dr99 { // dr99: sup 214 1170 template<typename T> void f(T&); 1171 template<typename T> int &f(const T&); 1172 const int n = 0; 1173 int &r = f(n); 1174 } 1175