dr2xx.cpp revision ad40edabcb1a6cf05c17c31e66842e3cbb24fde9
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++1y %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4
5#if __cplusplus < 201103L
6#define fold(x) (__builtin_constant_p(x) ? (x) : (x))
7#else
8#define fold
9#endif
10
11namespace dr200 { // dr200: dup 214
12  template <class T> T f(int);
13  template <class T, class U> T f(U) = delete; // expected-error 0-1{{extension}}
14
15  void g() {
16    f<int>(1);
17  }
18}
19
20// dr201 FIXME: write codegen test
21
22namespace dr202 { // dr202: yes
23  template<typename T> T f();
24  template<int (*g)()> struct X {
25    int arr[fold(g == &f<int>) ? 1 : -1];
26  };
27  template struct X<f>;
28}
29
30// FIXME (export) dr204: no
31
32namespace dr206 { // dr206: yes
33  struct S; // expected-note 2{{declaration}}
34  template<typename T> struct Q { S s; }; // expected-error {{incomplete}}
35  template<typename T> void f() { S s; } // expected-error {{incomplete}}
36}
37
38namespace dr207 { // dr207: yes
39  class A {
40  protected:
41    static void f() {}
42  };
43  class B : A {
44  public:
45    using A::f;
46    void g() {
47      A::f();
48      f();
49    }
50  };
51}
52
53// dr208 FIXME: write codegen test
54
55namespace dr209 { // dr209: yes
56  class A {
57    void f(); // expected-note {{here}}
58  };
59  class B {
60    friend void A::f(); // expected-error {{private}}
61  };
62}
63
64// dr210 FIXME: write codegen test
65
66namespace dr211 { // dr211: yes
67  struct A {
68    A() try {
69      throw 0;
70    } catch (...) {
71      return; // expected-error {{return in the catch of a function try block of a constructor}}
72    }
73  };
74}
75
76namespace dr213 { // dr213: yes
77  template <class T> struct A : T {
78    void h(T t) {
79      char &r1 = f(t);
80      int &r2 = g(t); // expected-error {{undeclared}}
81    }
82  };
83  struct B {
84    int &f(B);
85    int &g(B); // expected-note {{in dependent base class}}
86  };
87  char &f(B);
88
89  template void A<B>::h(B); // expected-note {{instantiation}}
90}
91
92namespace dr214 { // dr214: yes
93  template<typename T, typename U> T checked_cast(U from) { U::error; }
94  template<typename T, typename U> T checked_cast(U *from);
95  class C {};
96  void foo(int *arg) { checked_cast<const C *>(arg); }
97
98  template<typename T> T f(int);
99  template<typename T, typename U> T f(U) { T::error; }
100  void g() {
101    f<int>(1);
102  }
103}
104
105namespace dr215 { // dr215: yes
106  template<typename T> class X {
107    friend void T::foo();
108    int n;
109  };
110  struct Y {
111    void foo() { (void)+X<Y>().n; }
112  };
113}
114
115namespace dr216 { // dr216: no
116  // FIXME: Should reject this: 'f' has linkage but its type does not,
117  // and 'f' is odr-used but not defined in this TU.
118  typedef enum { e } *E;
119  void f(E);
120  void g(E e) { f(e); }
121
122  struct S {
123    // FIXME: Should reject this: 'f' has linkage but its type does not,
124    // and 'f' is odr-used but not defined in this TU.
125    typedef enum { e } *E;
126    void f(E);
127  };
128  void g(S s, S::E e) { s.f(e); }
129}
130
131namespace dr217 { // dr217: yes
132  template<typename T> struct S {
133    void f(int);
134  };
135  template<typename T> void S<T>::f(int = 0) {} // expected-error {{default arguments cannot be added}}
136}
137
138namespace dr218 { // dr218: yes
139  namespace A {
140    struct S {};
141    void f(S);
142  }
143  namespace B {
144    struct S {};
145    void f(S);
146  }
147
148  struct C {
149    int f;
150    void test1(A::S as) { f(as); } // expected-error {{called object type 'int'}}
151    void test2(A::S as) { void f(); f(as); } // expected-error {{too many arguments}} expected-note {{}}
152    void test3(A::S as) { using A::f; f(as); } // ok
153    void test4(A::S as) { using B::f; f(as); } // ok
154    void test5(A::S as) { int f; f(as); } // expected-error {{called object type 'int'}}
155    void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no matching conversion}} expected-note +{{}}
156  };
157
158  namespace D {
159    struct S {};
160    struct X { void operator()(S); } f;
161  }
162  void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}}
163
164  namespace E {
165    struct S {};
166    struct f { f(S); };
167  }
168  void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}}
169
170  namespace F {
171    struct S {
172      template<typename T> friend void f(S, T) {}
173    };
174  }
175  void testF(F::S fs) { f(fs, 0); }
176
177  namespace G {
178    namespace X {
179      int f;
180      struct A {};
181    }
182    namespace Y {
183      template<typename T> void f(T);
184      struct B {};
185    }
186    template<typename A, typename B> struct C {};
187  }
188  void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); }
189}
190
191// dr219: na
192// dr220: na
193
194namespace dr221 { // dr221: yes
195  struct A {
196    A &operator=(int&);
197    A &operator+=(int&);
198    static A &operator=(A&, double&); // expected-error {{cannot be a static member}}
199    static A &operator+=(A&, double&); // expected-error {{cannot be a static member}}
200    friend A &operator=(A&, char&); // expected-error {{must be a non-static member function}}
201    friend A &operator+=(A&, char&);
202  };
203  A &operator=(A&, float&); // expected-error {{must be a non-static member function}}
204  A &operator+=(A&, float&);
205
206  void test(A a, int n, char c, float f) {
207    a = n;
208    a += n;
209    a = c;
210    a += c;
211    a = f;
212    a += f;
213  }
214}
215
216// dr222 is a mystery -- it lists no changes to the standard, and yet was
217// apparently both voted into the WP and acted upon by the editor.
218
219// dr223: na
220