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