1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 4 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 5 6 // PR13819 -- __SIZE_TYPE__ is incompatible. 7 typedef __SIZE_TYPE__ size_t; // expected-error 0-1 {{extension}} 8 9 #if __cplusplus < 201103L 10 #define fold(x) (__builtin_constant_p(x) ? (x) : (x)) 11 #else 12 #define fold 13 #endif 14 15 namespace dr200 { // dr200: dup 214 16 template <class T> T f(int); 17 template <class T, class U> T f(U) = delete; // expected-error 0-1{{extension}} 18 19 void g() { 20 f<int>(1); 21 } 22 } 23 24 // dr201 FIXME: write codegen test 25 26 namespace dr202 { // dr202: yes 27 template<typename T> T f(); 28 template<int (*g)()> struct X { 29 int arr[fold(g == &f<int>) ? 1 : -1]; 30 }; 31 template struct X<f>; 32 } 33 34 // FIXME (export) dr204: no 35 36 namespace dr206 { // dr206: yes 37 struct S; // expected-note 2{{declaration}} 38 template<typename T> struct Q { S s; }; // expected-error {{incomplete}} 39 template<typename T> void f() { S s; } // expected-error {{incomplete}} 40 } 41 42 namespace dr207 { // dr207: yes 43 class A { 44 protected: 45 static void f() {} 46 }; 47 class B : A { 48 public: 49 using A::f; 50 void g() { 51 A::f(); 52 f(); 53 } 54 }; 55 } 56 57 // dr208 FIXME: write codegen test 58 59 namespace dr209 { // dr209: yes 60 class A { 61 void f(); // expected-note {{here}} 62 }; 63 class B { 64 friend void A::f(); // expected-error {{private}} 65 }; 66 } 67 68 // dr210 FIXME: write codegen test 69 70 namespace dr211 { // dr211: yes 71 struct A { 72 A() try { 73 throw 0; 74 } catch (...) { 75 return; // expected-error {{return in the catch of a function try block of a constructor}} 76 } 77 }; 78 } 79 80 namespace dr213 { // dr213: yes 81 template <class T> struct A : T { 82 void h(T t) { 83 char &r1 = f(t); 84 int &r2 = g(t); // expected-error {{undeclared}} 85 } 86 }; 87 struct B { 88 int &f(B); 89 int &g(B); // expected-note {{in dependent base class}} 90 }; 91 char &f(B); 92 93 template void A<B>::h(B); // expected-note {{instantiation}} 94 } 95 96 namespace dr214 { // dr214: yes 97 template<typename T, typename U> T checked_cast(U from) { U::error; } 98 template<typename T, typename U> T checked_cast(U *from); 99 class C {}; 100 void foo(int *arg) { checked_cast<const C *>(arg); } 101 102 template<typename T> T f(int); 103 template<typename T, typename U> T f(U) { T::error; } 104 void g() { 105 f<int>(1); 106 } 107 } 108 109 namespace dr215 { // dr215: yes 110 template<typename T> class X { 111 friend void T::foo(); 112 int n; 113 }; 114 struct Y { 115 void foo() { (void)+X<Y>().n; } 116 }; 117 } 118 119 namespace dr216 { // dr216: no 120 // FIXME: Should reject this: 'f' has linkage but its type does not, 121 // and 'f' is odr-used but not defined in this TU. 122 typedef enum { e } *E; 123 void f(E); 124 void g(E e) { f(e); } 125 126 struct S { 127 // FIXME: Should reject this: 'f' has linkage but its type does not, 128 // and 'f' is odr-used but not defined in this TU. 129 typedef enum { e } *E; 130 void f(E); 131 }; 132 void g(S s, S::E e) { s.f(e); } 133 } 134 135 namespace dr217 { // dr217: yes 136 template<typename T> struct S { 137 void f(int); 138 }; 139 template<typename T> void S<T>::f(int = 0) {} // expected-error {{default arguments cannot be added}} 140 } 141 142 namespace dr218 { // dr218: yes 143 namespace A { 144 struct S {}; 145 void f(S); 146 } 147 namespace B { 148 struct S {}; 149 void f(S); 150 } 151 152 struct C { 153 int f; 154 void test1(A::S as) { f(as); } // expected-error {{called object type 'int'}} 155 void test2(A::S as) { void f(); f(as); } // expected-error {{too many arguments}} expected-note {{}} 156 void test3(A::S as) { using A::f; f(as); } // ok 157 void test4(A::S as) { using B::f; f(as); } // ok 158 void test5(A::S as) { int f; f(as); } // expected-error {{called object type 'int'}} 159 void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no matching conversion}} expected-note +{{}} 160 }; 161 162 namespace D { 163 struct S {}; 164 struct X { void operator()(S); } f; 165 } 166 void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}} 167 168 namespace E { 169 struct S {}; 170 struct f { f(S); }; 171 } 172 void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}} 173 174 namespace F { 175 struct S { 176 template<typename T> friend void f(S, T) {} 177 }; 178 } 179 void testF(F::S fs) { f(fs, 0); } 180 181 namespace G { 182 namespace X { 183 int f; 184 struct A {}; 185 } 186 namespace Y { 187 template<typename T> void f(T); 188 struct B {}; 189 } 190 template<typename A, typename B> struct C {}; 191 } 192 void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); } 193 } 194 195 // dr219: na 196 // dr220: na 197 198 namespace dr221 { // dr221: yes 199 struct A { // expected-note 2-4{{candidate}} 200 A &operator=(int&); // expected-note 2{{candidate}} 201 A &operator+=(int&); 202 static A &operator=(A&, double&); // expected-error {{cannot be a static member}} 203 static A &operator+=(A&, double&); // expected-error {{cannot be a static member}} 204 friend A &operator=(A&, char&); // expected-error {{must be a non-static member function}} 205 friend A &operator+=(A&, char&); 206 }; 207 A &operator=(A&, float&); // expected-error {{must be a non-static member function}} 208 A &operator+=(A&, float&); 209 210 void test(A a, int n, char c, float f) { 211 a = n; 212 a += n; 213 a = c; // expected-error {{no viable}} 214 a += c; 215 a = f; // expected-error {{no viable}} 216 a += f; 217 } 218 } 219 220 namespace dr222 { // dr222: dup 637 221 void f(int a, int b, int c, int *x) { 222 #pragma clang diagnostic push 223 #pragma clang diagnostic warning "-Wunsequenced" 224 void((a += b) += c); 225 void((a += b) + (a += c)); // expected-warning {{multiple unsequenced modifications to 'a'}} 226 227 x[a++] = a; // expected-warning {{unsequenced modification and access to 'a'}} 228 229 a = b = 0; // ok, read and write of 'b' are sequenced 230 231 a = (b = a++); // expected-warning {{multiple unsequenced modifications to 'a'}} 232 a = (b = ++a); 233 #pragma clang diagnostic pop 234 } 235 } 236 237 // dr223: na 238 239 namespace dr224 { // dr224: no 240 namespace example1 { 241 template <class T> class A { 242 typedef int type; 243 A::type a; 244 A<T>::type b; 245 A<T*>::type c; // expected-error {{missing 'typename'}} 246 ::dr224::example1::A<T>::type d; 247 248 class B { 249 typedef int type; 250 251 A::type a; 252 A<T>::type b; 253 A<T*>::type c; // expected-error {{missing 'typename'}} 254 ::dr224::example1::A<T>::type d; 255 256 B::type e; 257 A<T>::B::type f; 258 A<T*>::B::type g; // expected-error {{missing 'typename'}} 259 typename A<T*>::B::type h; 260 }; 261 }; 262 263 template <class T> class A<T*> { 264 typedef int type; 265 A<T*>::type a; 266 A<T>::type b; // expected-error {{missing 'typename'}} 267 }; 268 269 template <class T1, class T2, int I> struct B { 270 typedef int type; 271 B<T1, T2, I>::type b1; 272 B<T2, T1, I>::type b2; // expected-error {{missing 'typename'}} 273 274 typedef T1 my_T1; 275 static const int my_I = I; 276 static const int my_I2 = I+0; 277 static const int my_I3 = my_I; 278 B<my_T1, T2, my_I>::type b3; // FIXME: expected-error {{missing 'typename'}} 279 B<my_T1, T2, my_I2>::type b4; // expected-error {{missing 'typename'}} 280 B<my_T1, T2, my_I3>::type b5; // FIXME: expected-error {{missing 'typename'}} 281 }; 282 } 283 284 namespace example2 { 285 template <int, typename T> struct X { typedef T type; }; 286 template <class T> class A { 287 static const int i = 5; 288 X<i, int>::type w; // FIXME: expected-error {{missing 'typename'}} 289 X<A::i, char>::type x; // FIXME: expected-error {{missing 'typename'}} 290 X<A<T>::i, double>::type y; // FIXME: expected-error {{missing 'typename'}} 291 X<A<T*>::i, long>::type z; // expected-error {{missing 'typename'}} 292 int f(); 293 }; 294 template <class T> int A<T>::f() { 295 return i; 296 } 297 } 298 } 299 300 // dr225: yes 301 template<typename T> void dr225_f(T t) { dr225_g(t); } // expected-error {{call to function 'dr225_g' that is neither visible in the template definition nor found by argument-dependent lookup}} 302 void dr225_g(int); // expected-note {{should be declared prior to the call site}} 303 template void dr225_f(int); // expected-note {{in instantiation of}} 304 305 namespace dr226 { // dr226: no 306 template<typename T = void> void f() {} 307 #if __cplusplus < 201103L 308 // expected-error@-2 {{extension}} 309 // FIXME: This appears to be wrong: default arguments for function templates 310 // are listed as a defect (in c++98) not an extension. EDG accepts them in 311 // strict c++98 mode. 312 #endif 313 template<typename T> struct S { 314 template<typename U = void> void g(); 315 #if __cplusplus < 201103L 316 // expected-error@-2 {{extension}} 317 #endif 318 template<typename U> struct X; 319 template<typename U> void h(); 320 }; 321 template<typename T> template<typename U> void S<T>::g() {} 322 template<typename T> template<typename U = void> struct S<T>::X {}; // expected-error {{cannot add a default template arg}} 323 template<typename T> template<typename U = void> void S<T>::h() {} // expected-error {{cannot add a default template arg}} 324 325 template<typename> void friend_h(); 326 struct A { 327 // FIXME: This is ill-formed. 328 template<typename=void> struct friend_B; 329 // FIXME: f, h, and i are ill-formed. 330 // f is ill-formed because it is not a definition. 331 // h and i are ill-formed because they are not the only declarations of the 332 // function in the translation unit. 333 template<typename=void> void friend_f(); 334 template<typename=void> void friend_g() {} 335 template<typename=void> void friend_h() {} 336 template<typename=void> void friend_i() {} 337 #if __cplusplus < 201103L 338 // expected-error@-5 {{extension}} expected-error@-4 {{extension}} 339 // expected-error@-4 {{extension}} expected-error@-3 {{extension}} 340 #endif 341 }; 342 template<typename> void friend_i(); 343 344 template<typename=void, typename X> void foo(X) {} 345 template<typename=void, typename X> struct Foo {}; // expected-error {{missing a default argument}} expected-note {{here}} 346 #if __cplusplus < 201103L 347 // expected-error@-3 {{extension}} 348 #endif 349 350 template<typename=void, typename X, typename, typename Y> int foo(X, Y); 351 template<typename, typename X, typename=void, typename Y> int foo(X, Y); 352 int x = foo(0, 0); 353 #if __cplusplus < 201103L 354 // expected-error@-4 {{extension}} 355 // expected-error@-4 {{extension}} 356 #endif 357 } 358 359 void dr227(bool b) { // dr227: yes 360 if (b) 361 int n; 362 else 363 int n; 364 } 365 366 namespace dr228 { // dr228: yes 367 template <class T> struct X { 368 void f(); 369 }; 370 template <class T> struct Y { 371 void g(X<T> x) { x.template X<T>::f(); } 372 }; 373 } 374 375 namespace dr229 { // dr229: yes 376 template<typename T> void f(); 377 template<typename T> void f<T*>() {} // expected-error {{function template partial specialization}} 378 template<> void f<int>() {} 379 } 380 381 namespace dr230 { // dr230: yes 382 struct S { 383 S() { f(); } // expected-warning {{call to pure virtual member function}} 384 virtual void f() = 0; // expected-note {{declared here}} 385 }; 386 } 387 388 namespace dr231 { // dr231: yes 389 namespace outer { 390 namespace inner { 391 int i; // expected-note {{here}} 392 } 393 void f() { using namespace inner; } 394 int j = i; // expected-error {{undeclared identifier 'i'; did you mean 'inner::i'?}} 395 } 396 } 397 398 // dr234: na 399 // dr235: na 400 401 namespace dr236 { // dr236: yes 402 void *p = int(); 403 #if __cplusplus < 201103L 404 // expected-warning@-2 {{null pointer}} 405 #else 406 // expected-error@-4 {{cannot initialize}} 407 #endif 408 } 409 410 namespace dr237 { // dr237: dup 470 411 template<typename T> struct A { void f() { T::error; } }; 412 template<typename T> struct B : A<T> {}; 413 template struct B<int>; // ok 414 } 415 416 namespace dr239 { // dr239: yes 417 namespace NS { 418 class T {}; 419 void f(T); 420 float &g(T, int); 421 } 422 NS::T parm; 423 int &g(NS::T, float); 424 int main() { 425 f(parm); 426 float &r = g(parm, 1); 427 extern int &g(NS::T, float); 428 int &s = g(parm, 1); 429 } 430 } 431 432 // dr240: dup 616 433 434 namespace dr241 { // dr241: yes 435 namespace A { 436 struct B {}; 437 template <int X> void f(); // expected-note 2{{candidate}} 438 template <int X> void g(B); 439 } 440 namespace C { 441 template <class T> void f(T t); // expected-note 2{{candidate}} 442 template <class T> void g(T t); // expected-note {{candidate}} 443 } 444 void h(A::B b) { 445 f<3>(b); // expected-error {{undeclared identifier}} 446 g<3>(b); // expected-error {{undeclared identifier}} 447 A::f<3>(b); // expected-error {{no matching}} 448 A::g<3>(b); 449 C::f<3>(b); // expected-error {{no matching}} 450 C::g<3>(b); // expected-error {{no matching}} 451 using C::f; 452 using C::g; 453 f<3>(b); // expected-error {{no matching}} 454 g<3>(b); 455 } 456 } 457 458 namespace dr243 { // dr243: yes 459 struct B; 460 struct A { 461 A(B); // expected-note {{candidate}} 462 }; 463 struct B { 464 operator A() = delete; // expected-error 0-1{{extension}} expected-note {{candidate}} 465 } b; 466 A a1(b); 467 A a2 = b; // expected-error {{ambiguous}} 468 } 469 470 namespace dr244 { // dr244: partial 471 struct B {}; struct D : B {}; // expected-note {{here}} 472 473 D D_object; 474 typedef B B_alias; 475 B* B_ptr = &D_object; 476 477 void f() { 478 D_object.~B(); // expected-error {{expression does not match the type}} 479 D_object.B::~B(); 480 B_ptr->~B(); 481 B_ptr->~B_alias(); 482 B_ptr->B_alias::~B(); 483 // This is valid under DR244. 484 B_ptr->B_alias::~B_alias(); 485 B_ptr->dr244::~B(); // expected-error {{refers to a member in namespace}} 486 B_ptr->dr244::~B_alias(); // expected-error {{refers to a member in namespace}} 487 } 488 489 namespace N { 490 template<typename T> struct E {}; 491 typedef E<int> F; 492 } 493 void g(N::F f) { 494 typedef N::F G; 495 f.~G(); 496 f.G::~E(); 497 f.G::~F(); // expected-error {{expected the class name after '~' to name a destructor}} 498 f.G::~G(); 499 // This is technically ill-formed; E is looked up in 'N::' and names the 500 // class template, not the injected-class-name of the class. But that's 501 // probably a bug in the standard. 502 f.N::F::~E(); 503 // This is valid; we look up the second F in the same scope in which we 504 // found the first one, that is, 'N::'. 505 f.N::F::~F(); // FIXME: expected-error {{expected the class name after '~' to name a destructor}} 506 // This is technically ill-formed; G is looked up in 'N::' and is not found; 507 // as above, this is probably a bug in the standard. 508 f.N::F::~G(); 509 } 510 } 511 512 namespace dr245 { // dr245: yes 513 struct S { 514 enum E {}; // expected-note {{here}} 515 class E *p; // expected-error {{does not match previous declaration}} 516 }; 517 } 518 519 namespace dr246 { // dr246: yes 520 struct S { 521 S() try { // expected-note {{try block}} 522 throw 0; 523 X: ; 524 } catch (int) { 525 goto X; // expected-error {{cannot jump}} 526 } 527 }; 528 } 529 530 namespace dr247 { // dr247: yes 531 struct A {}; 532 struct B : A { 533 void f(); 534 void f(int); 535 }; 536 void (A::*f)() = (void (A::*)())&B::f; 537 538 struct C { 539 void f(); 540 void f(int); 541 }; 542 struct D : C {}; 543 void (C::*g)() = &D::f; 544 void (D::*h)() = &D::f; 545 546 struct E { 547 void f(); 548 }; 549 struct F : E { 550 using E::f; 551 void f(int); 552 }; 553 void (F::*i)() = &F::f; 554 } 555 556 namespace dr248 { // dr248: yes c++11 557 // FIXME: Should this also apply to c++98 mode? This was a DR against C++98. 558 int \u040d\u040e = 0; 559 #if __cplusplus < 201103L 560 // FIXME: expected-error@-2 {{expected ';'}} 561 #endif 562 } 563 564 namespace dr249 { // dr249: yes 565 template<typename T> struct X { void f(); }; 566 template<typename T> void X<T>::f() {} 567 } 568 569 namespace dr250 { // dr250: yes 570 typedef void (*FPtr)(double x[]); 571 572 template<int I> void f(double x[]); 573 FPtr fp = &f<3>; 574 575 template<int I = 3> void g(double x[]); // expected-error 0-1{{extension}} 576 FPtr gp = &g<>; 577 } 578 579 namespace dr252 { // dr252: yes 580 struct A { 581 void operator delete(void*); // expected-note {{found}} 582 }; 583 struct B { 584 void operator delete(void*); // expected-note {{found}} 585 }; 586 struct C : A, B { 587 virtual ~C(); 588 }; 589 C::~C() {} // expected-error {{'operator delete' found in multiple base classes}} 590 591 struct D { 592 void operator delete(void*, int); // expected-note {{here}} 593 virtual ~D(); 594 }; 595 D::~D() {} // expected-error {{no suitable member 'operator delete'}} 596 597 struct E { 598 void operator delete(void*, int); 599 void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note 1-2 {{here}} 600 virtual ~E(); // expected-error 0-1 {{attempt to use a deleted function}} 601 }; 602 E::~E() {} // expected-error {{attempt to use a deleted function}} 603 604 struct F { 605 // If both functions are available, the first one is a placement delete. 606 void operator delete(void*, size_t); 607 void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note {{here}} 608 virtual ~F(); 609 }; 610 F::~F() {} // expected-error {{attempt to use a deleted function}} 611 612 struct G { 613 void operator delete(void*, size_t); 614 virtual ~G(); 615 }; 616 G::~G() {} 617 } 618 619 namespace dr254 { // dr254: yes 620 template<typename T> struct A { 621 typedef typename T::type type; // ok even if this is a typedef-name, because 622 // it's not an elaborated-type-specifier 623 typedef struct T::type foo; // expected-error {{elaborated type refers to a typedef}} 624 }; 625 struct B { struct type {}; }; 626 struct C { typedef struct {} type; }; // expected-note {{here}} 627 A<B>::type n; 628 A<C>::type n; // expected-note {{instantiation of}} 629 } 630 631 // dr256: dup 624 632 633 namespace dr257 { // dr257: yes 634 struct A { A(int); }; // expected-note {{here}} 635 struct B : virtual A { 636 B() {} 637 virtual void f() = 0; 638 }; 639 struct C : B { 640 C() {} 641 }; 642 struct D : B { 643 D() {} // expected-error {{must explicitly initialize the base class 'dr257::A'}} 644 void f(); 645 }; 646 } 647 648 namespace dr258 { // dr258: yes 649 struct A { 650 void f(const int); 651 template<typename> void g(int); 652 float &h() const; 653 }; 654 struct B : A { 655 using A::f; 656 using A::g; 657 using A::h; 658 int &f(int); 659 template<int> int &g(int); // expected-note {{candidate}} 660 int &h(); 661 } b; 662 int &w = b.f(0); 663 int &x = b.g<int>(0); // expected-error {{no match}} 664 int &y = b.h(); 665 float &z = const_cast<const B&>(b).h(); 666 667 struct C { 668 virtual void f(const int) = 0; 669 }; 670 struct D : C { 671 void f(int); 672 } d; 673 674 struct E { 675 virtual void f() = 0; // expected-note {{unimplemented}} 676 }; 677 struct F : E { 678 void f() const {} 679 } f; // expected-error {{abstract}} 680 } 681 682 namespace dr259 { // dr259: yes c++11 683 template<typename T> struct A {}; 684 template struct A<int>; // expected-note {{previous}} 685 template struct A<int>; // expected-error {{duplicate explicit instantiation}} 686 687 // FIXME: We only apply this DR in C++11 mode. 688 template<> struct A<float>; 689 template struct A<float>; 690 #if __cplusplus < 201103L 691 // expected-error@-2 {{extension}} expected-note@-3 {{here}} 692 #endif 693 694 template struct A<char>; // expected-note {{here}} 695 template<> struct A<char>; // expected-error {{explicit specialization of 'dr259::A<char>' after instantiation}} 696 697 template<> struct A<double>; 698 template<> struct A<double>; 699 template<> struct A<double> {}; // expected-note {{here}} 700 template<> struct A<double> {}; // expected-error {{redefinition}} 701 702 template<typename T> struct B; // expected-note {{here}} 703 template struct B<int>; // expected-error {{undefined}} 704 705 template<> struct B<float>; 706 template struct B<float>; 707 #if __cplusplus < 201103L 708 // expected-error@-2 {{extension}} expected-note@-3 {{here}} 709 #endif 710 } 711 712 // FIXME: When dr260 is resolved, also add tests for DR507. 713 714 namespace dr261 { // dr261: no 715 #pragma clang diagnostic push 716 #pragma clang diagnostic warning "-Wused-but-marked-unused" 717 718 // FIXME: This is ill-formed, with a diagnostic required, because operator new 719 // and operator delete are inline and odr-used, but not defined in this 720 // translation unit. 721 // We're also missing the -Wused-but-marked-unused diagnostic here. 722 struct A { 723 inline void *operator new(size_t) __attribute__((unused)); 724 inline void operator delete(void*) __attribute__((unused)); 725 A() {} 726 }; 727 728 // FIXME: These are ill-formed, with a required diagnostic, for the same 729 // reason. 730 struct B { 731 inline void operator delete(void*) __attribute__((unused)); 732 ~B() {} 733 }; 734 struct C { 735 inline void operator delete(void*) __attribute__((unused)); 736 virtual ~C() {} 737 }; 738 739 struct D { 740 inline void operator delete(void*) __attribute__((unused)); 741 }; 742 void h() { C::operator delete(0); } // expected-warning {{marked unused but was used}} 743 744 #pragma clang diagnostic pop 745 } 746 747 namespace dr262 { // dr262: yes 748 int f(int = 0, ...); 749 int k = f(); 750 int l = f(0); 751 int m = f(0, 0); 752 } 753 754 namespace dr263 { // dr263: yes 755 struct X {}; 756 struct Y { 757 #if __cplusplus < 201103L 758 friend X::X() throw(); 759 friend X::~X() throw(); 760 #else 761 friend constexpr X::X() noexcept; 762 friend X::~X(); 763 #endif 764 Y::Y(); // expected-error {{extra qualification}} 765 Y::~Y(); // expected-error {{extra qualification}} 766 }; 767 } 768 769 // dr265: dup 353 770 // dr266: na 771 // dr269: na 772 // dr270: na 773 774 namespace dr272 { // dr272: yes 775 struct X { 776 void f() { 777 this->~X(); 778 X::~X(); 779 ~X(); // expected-error {{unary expression}} 780 } 781 }; 782 } 783 784 #include <stdarg.h> 785 #include <stddef.h> 786 namespace dr273 { // dr273: yes 787 struct A { 788 int n; 789 }; 790 void operator&(A); 791 void f(A a, ...) { 792 offsetof(A, n); 793 va_list val; 794 va_start(val, a); 795 va_end(val); 796 } 797 } 798 799 // dr274: na 800 801 namespace dr275 { // dr275: no 802 namespace N { 803 template <class T> void f(T) {} // expected-note 1-4{{here}} 804 template <class T> void g(T) {} // expected-note {{candidate}} 805 template <> void f(int); 806 template <> void f(char); 807 template <> void f(double); 808 template <> void g(char); 809 } 810 811 using namespace N; 812 813 namespace M { 814 template <> void N::f(char) {} // expected-error {{'M' does not enclose namespace 'N'}} 815 template <class T> void g(T) {} 816 template <> void g(char) {} 817 template void f(long); 818 #if __cplusplus >= 201103L 819 // FIXME: this should be rejected in c++98 too 820 // expected-error@-3 {{must occur in namespace 'N'}} 821 #endif 822 template void N::f(unsigned long); 823 #if __cplusplus >= 201103L 824 // FIXME: this should be rejected in c++98 too 825 // expected-error@-3 {{not in a namespace enclosing 'N'}} 826 #endif 827 template void h(long); // expected-error {{does not refer to a function template}} 828 template <> void f(double) {} // expected-error {{no function template matches}} 829 } 830 831 template <class T> void g(T) {} // expected-note {{candidate}} 832 833 template <> void N::f(char) {} 834 template <> void f(int) {} // expected-error {{no function template matches}} 835 836 template void f(short); 837 #if __cplusplus >= 201103L 838 // FIXME: this should be rejected in c++98 too 839 // expected-error@-3 {{must occur in namespace 'N'}} 840 #endif 841 template void N::f(unsigned short); 842 843 // FIXME: this should probably be valid. the wording from the issue 844 // doesn't clarify this, but it follows from the usual rules. 845 template void g(int); // expected-error {{ambiguous}} 846 847 // FIXME: likewise, this should also be valid. 848 template<typename T> void f(T) {} // expected-note {{candidate}} 849 template void f(short); // expected-error {{ambiguous}} 850 } 851 852 // dr276: na 853 854 namespace dr277 { // dr277: yes 855 typedef int *intp; 856 int *p = intp(); 857 int a[fold(intp() ? -1 : 1)]; 858 } 859 860 namespace dr280 { // dr280: yes 861 typedef void f0(); 862 typedef void f1(int); 863 typedef void f2(int, int); 864 typedef void f3(int, int, int); 865 struct A { 866 operator f1*(); // expected-note {{here}} expected-note {{candidate}} 867 operator f2*(); 868 }; 869 struct B { 870 operator f0*(); // expected-note {{candidate}} 871 private: 872 operator f3*(); // expected-note {{here}} expected-note {{candidate}} 873 }; 874 struct C { 875 operator f0*(); // expected-note {{candidate}} 876 operator f1*(); // expected-note {{candidate}} 877 operator f2*(); // expected-note {{candidate}} 878 operator f3*(); // expected-note {{candidate}} 879 }; 880 struct D : private A, B { // expected-note 2{{here}} 881 operator f2*(); // expected-note {{candidate}} 882 } d; 883 struct E : C, D {} e; 884 void g() { 885 d(); // ok, public 886 d(0); // expected-error {{private member of 'dr280::A'}} expected-error {{private base class 'dr280::A'}} 887 d(0, 0); // ok, suppressed by member in D 888 d(0, 0, 0); // expected-error {{private member of 'dr280::B'}} 889 e(); // expected-error {{ambiguous}} 890 e(0); // expected-error {{ambiguous}} 891 e(0, 0); // expected-error {{ambiguous}} 892 e(0, 0, 0); // expected-error {{ambiguous}} 893 } 894 } 895 896 namespace dr281 { // dr281: no 897 void a(); 898 inline void b(); 899 900 void d(); 901 inline void e(); 902 903 struct S { 904 friend inline void a(); // FIXME: ill-formed 905 friend inline void b(); 906 friend inline void c(); // FIXME: ill-formed 907 friend inline void d() {} 908 friend inline void e() {} 909 friend inline void f() {} 910 }; 911 } 912 913 namespace dr283 { // dr283: yes 914 template<typename T> // expected-note 2{{here}} 915 struct S { 916 friend class T; // expected-error {{shadows}} 917 class T; // expected-error {{shadows}} 918 }; 919 } 920 921 namespace dr284 { // dr284: no 922 namespace A { 923 struct X; 924 enum Y {}; 925 class Z {}; 926 } 927 namespace B { 928 struct W; 929 using A::X; 930 using A::Y; 931 using A::Z; 932 } 933 struct B::V {}; // expected-error {{no struct named 'V'}} 934 struct B::W {}; 935 struct B::X {}; // FIXME: ill-formed 936 enum B::Y e; // ok per dr417 937 class B::Z z; // ok per dr417 938 939 struct C { 940 struct X; 941 enum Y {}; 942 class Z {}; 943 }; 944 struct D : C { 945 struct W; 946 using C::X; 947 using C::Y; 948 using C::Z; 949 }; 950 struct D::V {}; // expected-error {{no struct named 'V'}} 951 struct D::W {}; 952 struct D::X {}; // FIXME: ill-formed 953 enum D::Y e2; // ok per dr417 954 class D::Z z2; // ok per dr417 955 } 956 957 namespace dr285 { // dr285: yes 958 template<typename T> void f(T, int); // expected-note {{match}} 959 template<typename T> void f(int, T); // expected-note {{match}} 960 template<> void f<int>(int, int) {} // expected-error {{ambiguous}} 961 } 962 963 namespace dr286 { // dr286: yes 964 template<class T> struct A { 965 class C { 966 template<class T2> struct B {}; // expected-note {{here}} 967 }; 968 }; 969 970 template<class T> 971 template<class T2> 972 struct A<T>::C::B<T2*> { }; 973 974 A<short>::C::B<int*> absip; // expected-error {{private}} 975 } 976 977 // dr288: na 978 979 namespace dr289 { // dr289: yes 980 struct A; // expected-note {{forward}} 981 struct B : A {}; // expected-error {{incomplete}} 982 983 template<typename T> struct C { typename T::error error; }; // expected-error {{cannot be used prior to '::'}} 984 struct D : C<int> {}; // expected-note {{instantiation}} 985 } 986 987 // dr290: na 988 // dr291: dup 391 989 // dr292 FIXME: write a codegen test 990 991 namespace dr294 { // dr294: no 992 void f() throw(int); 993 int main() { 994 (void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed 995 (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed 996 997 void (*p)() throw() = f; // expected-error {{not superset}} 998 void (*q)() throw(int) = f; 999 } 1000 } 1001 1002 namespace dr295 { // dr295: 3.7 1003 typedef int f(); 1004 const f g; // expected-warning {{'const' qualifier on function type 'f' (aka 'int ()') has no effect}} 1005 f &r = g; 1006 template<typename T> struct X { 1007 const T &f; 1008 }; 1009 X<f> x = {g}; 1010 1011 typedef int U(); 1012 typedef const U U; // expected-warning {{'const' qualifier on function type 'U' (aka 'int ()') has no effect}} 1013 1014 typedef int (*V)(); 1015 typedef volatile U *V; // expected-warning {{'volatile' qualifier on function type 'U' (aka 'int ()') has no effect}} 1016 } 1017 1018 namespace dr296 { // dr296: yes 1019 struct A { 1020 static operator int() { return 0; } // expected-error {{static}} 1021 }; 1022 } 1023 1024 namespace dr298 { // dr298: yes 1025 struct A { 1026 typedef int type; 1027 A(); 1028 ~A(); 1029 }; 1030 typedef A B; // expected-note {{here}} 1031 typedef const A C; // expected-note {{here}} 1032 1033 A::type i1; 1034 B::type i2; 1035 C::type i3; 1036 1037 struct A a; 1038 struct B b; // expected-error {{refers to a typedef}} 1039 struct C c; // expected-error {{refers to a typedef}} 1040 1041 B::B() {} // expected-error {{requires a type specifier}} 1042 B::A() {} // ok 1043 C::~C() {} // expected-error {{destructor cannot be declared using a typedef 'C' (aka 'const dr298::A') of the class name}} 1044 1045 typedef struct D E; // expected-note {{here}} 1046 struct E {}; // expected-error {{conflicts with typedef}} 1047 1048 struct F { 1049 ~F(); 1050 }; 1051 typedef const F G; 1052 G::~F() {} // ok 1053 } 1054 1055 namespace dr299 { // dr299: yes c++11 1056 struct S { 1057 operator int(); 1058 }; 1059 struct T { 1060 operator int(); // expected-note {{}} 1061 operator unsigned short(); // expected-note {{}} 1062 }; 1063 // FIXME: should this apply to c++98 mode? 1064 int *p = new int[S()]; // expected-error 0-1{{extension}} 1065 int *q = new int[T()]; // expected-error {{ambiguous}} 1066 } 1067