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