dr2xx.cpp revision 2c1721f12297bb881f7f9deb383fe6616d835272
1e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith// RUN: %clang_cc1 -std=c++1y %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith
52c1721f12297bb881f7f9deb383fe6616d835272Richard Smith#if __cplusplus < 201103L
62c1721f12297bb881f7f9deb383fe6616d835272Richard Smith#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
72c1721f12297bb881f7f9deb383fe6616d835272Richard Smith#else
82c1721f12297bb881f7f9deb383fe6616d835272Richard Smith#define fold
92c1721f12297bb881f7f9deb383fe6616d835272Richard Smith#endif
102c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
11e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smithnamespace dr200 { // dr200: dup 214
12e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith  template <class T> T f(int);
13e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith  template <class T, class U> T f(U) = delete; // expected-error 0-1{{extension}}
14e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith
15e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith  void g() {
16e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith    f<int>(1);
17e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith  }
18e9a5b3871f3d58fa226910fd8123c98fc8bc6c67Richard Smith}
192c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
202c1721f12297bb881f7f9deb383fe6616d835272Richard Smith// dr201 FIXME: write codegen test
212c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
222c1721f12297bb881f7f9deb383fe6616d835272Richard Smithnamespace dr202 { // dr202: yes
232c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<typename T> T f();
242c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<int (*g)()> struct X {
252c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    int arr[fold(g == &f<int>) ? 1 : -1];
262c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
272c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template struct X<f>;
282c1721f12297bb881f7f9deb383fe6616d835272Richard Smith}
292c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
302c1721f12297bb881f7f9deb383fe6616d835272Richard Smith// FIXME (export) dr204: no
312c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
322c1721f12297bb881f7f9deb383fe6616d835272Richard Smithnamespace dr206 { // dr206: yes
332c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  struct S; // expected-note 2{{declaration}}
342c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<typename T> struct Q { S s; }; // expected-error {{incomplete}}
352c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<typename T> void f() { S s; } // expected-error {{incomplete}}
362c1721f12297bb881f7f9deb383fe6616d835272Richard Smith}
372c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
382c1721f12297bb881f7f9deb383fe6616d835272Richard Smithnamespace dr207 { // dr207: yes
392c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  class A {
402c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  protected:
412c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    static void f() {}
422c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
432c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  class B : A {
442c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  public:
452c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    using A::f;
462c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    void g() {
472c1721f12297bb881f7f9deb383fe6616d835272Richard Smith      A::f();
482c1721f12297bb881f7f9deb383fe6616d835272Richard Smith      f();
492c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    }
502c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
512c1721f12297bb881f7f9deb383fe6616d835272Richard Smith}
522c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
532c1721f12297bb881f7f9deb383fe6616d835272Richard Smith// dr208 FIXME: write codegen test
542c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
552c1721f12297bb881f7f9deb383fe6616d835272Richard Smithnamespace dr209 { // dr209: yes
562c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  class A {
572c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    void f(); // expected-note {{here}}
582c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
592c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  class B {
602c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    friend void A::f(); // expected-error {{private}}
612c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
622c1721f12297bb881f7f9deb383fe6616d835272Richard Smith}
632c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
642c1721f12297bb881f7f9deb383fe6616d835272Richard Smith// dr210 FIXME: write codegen test
652c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
662c1721f12297bb881f7f9deb383fe6616d835272Richard Smithnamespace dr211 { // dr211: yes
672c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  struct A {
682c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    A() try {
692c1721f12297bb881f7f9deb383fe6616d835272Richard Smith      throw 0;
702c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    } catch (...) {
712c1721f12297bb881f7f9deb383fe6616d835272Richard Smith      return; // expected-error {{return in the catch of a function try block of a constructor}}
722c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    }
732c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
742c1721f12297bb881f7f9deb383fe6616d835272Richard Smith}
752c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
762c1721f12297bb881f7f9deb383fe6616d835272Richard Smithnamespace dr213 { // dr213: yes
772c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template <class T> struct A : T {
782c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    void h(T t) {
792c1721f12297bb881f7f9deb383fe6616d835272Richard Smith      char &r1 = f(t);
802c1721f12297bb881f7f9deb383fe6616d835272Richard Smith      int &r2 = g(t); // expected-error {{undeclared}}
812c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    }
822c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
832c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  struct B {
842c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    int &f(B);
852c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    int &g(B); // expected-note {{in dependent base class}}
862c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
872c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  char &f(B);
882c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
892c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template void A<B>::h(B); // expected-note {{instantiation}}
902c1721f12297bb881f7f9deb383fe6616d835272Richard Smith}
912c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
922c1721f12297bb881f7f9deb383fe6616d835272Richard Smithnamespace dr214 { // dr214: yes
932c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<typename T, typename U> T checked_cast(U from) { U::error; }
942c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<typename T, typename U> T checked_cast(U *from);
952c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  class C {};
962c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  void foo(int *arg) { checked_cast<const C *>(arg); }
972c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
982c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<typename T> T f(int);
992c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<typename T, typename U> T f(U) { T::error; }
1002c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  void g() {
1012c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    f<int>(1);
1022c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  }
1032c1721f12297bb881f7f9deb383fe6616d835272Richard Smith}
1042c1721f12297bb881f7f9deb383fe6616d835272Richard Smith
1052c1721f12297bb881f7f9deb383fe6616d835272Richard Smithnamespace dr215 { // dr215: yes
1062c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  template<typename T> class X {
1072c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    friend void T::foo();
1082c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    int n;
1092c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
1102c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  struct Y {
1112c1721f12297bb881f7f9deb383fe6616d835272Richard Smith    void foo() { (void)+X<Y>().n; }
1122c1721f12297bb881f7f9deb383fe6616d835272Richard Smith  };
1132c1721f12297bb881f7f9deb383fe6616d835272Richard Smith}
114