• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace dr100 { // dr100: yes
6   template<const char *> struct A {}; // expected-note {{declared here}}
7   template<const char (&)[4]> struct B {}; // expected-note {{declared here}}
8   A<"foo"> a; // expected-error {{does not refer to any declaration}}
9   B<"bar"> b; // expected-error {{does not refer to any declaration}}
10 }
11 
12 namespace dr101 { // dr101: yes
13   extern "C" void dr101_f();
14   typedef unsigned size_t;
15   namespace X {
16     extern "C" void dr101_f();
17     typedef unsigned size_t;
18   }
19   using X::dr101_f;
20   using X::size_t;
21 }
22 
23 namespace dr102 { // dr102: yes
24   namespace A {
f(T a,T b)25     template<typename T> T f(T a, T b) { return a + b; } // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
26   }
27   namespace B {
28     struct S {};
29   }
30   B::S operator+(B::S, B::S); // expected-note {{should be declared prior to the call site or in namespace 'dr102::B'}}
31   template B::S A::f(B::S, B::S); // expected-note {{in instantiation of}}
32 }
33 
34 // dr103: na
35 // dr104 FIXME: add codegen test
36 // dr105: na
37 
38 namespace dr106 { // dr106: sup 540
39   typedef int &r1;
40   typedef r1 &r1;
41   typedef const r1 r1;
42   typedef const r1 &r1;
43 
44   typedef const int &r2;
45   typedef r2 &r2;
46   typedef const r2 r2;
47   typedef const r2 &r2;
48 }
49 
50 namespace dr107 { // dr107: yes
51   struct S {};
operator +(S,S)52   extern "C" S operator+(S, S) { return S(); }
53 }
54 
55 namespace dr108 { // dr108: yes
56   template<typename T> struct A {
57     struct B { typedef int X; };
58     B::X x; // expected-error {{missing 'typename'}}
59     struct C : B { X x; }; // expected-error {{unknown type name}}
60   };
61   template<> struct A<int>::B { int X; };
62 }
63 
64 namespace dr109 { // dr109: yes
65   struct A { template<typename T> void f(T); };
66   template<typename T> struct B : T {
67     using T::template f; // expected-error {{using declaration can not refer to a template}}
gdr109::B68     void g() { this->f<int>(123); } // expected-error {{use 'template'}}
69   };
70 }
71 
72 namespace dr111 { // dr111: dup 535
73   struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); };
74   struct B : A { B(); }; // expected-note {{would lose const qualifier}} expected-note {{requires 0 arguments}}
75   const B b1;
76   B b2(b1); // expected-error {{no matching constructor}}
77 }
78 
79 namespace dr112 { // dr112: yes
80   struct T { int n; };
81   typedef T Arr[1];
82 
83   const T a1[1] = {};
84   volatile T a2[1] = {};
85   const Arr a3 = {};
86   volatile Arr a4 = {};
87   template<const volatile T*> struct X {};
88   X<a1> x1;
89   X<a2> x2;
90   X<a3> x3;
91   X<a4> x4;
92 #if __cplusplus < 201103L
93   // expected-error@-5 {{internal linkage}} expected-note@-10 {{here}}
94   // expected-error@-4 {{internal linkage}} expected-note@-9 {{here}}
95 #else
96   // FIXME: Test this somehow.
97 #endif
98 }
99 
100 namespace dr113 { // dr113: yes
101   extern void (*p)();
f()102   void f() {
103     no_such_function(); // expected-error {{undeclared}}
104     p();
105   }
106   void g();
107   void (*p)() = &g;
108 }
109 
110 namespace dr114 { // dr114: yes
111   struct A {
112     virtual void f(int) = 0; // expected-note {{unimplemented}}
113   };
114   struct B : A {
115     template<typename T> void f(T);
gdr114::B116     void g() { f(0); }
117   } b; // expected-error {{abstract}}
118 }
119 
120 namespace dr115 { // dr115: yes
121   template<typename T> int f(T); // expected-note +{{}}
122   template<typename T> int g(T); // expected-note +{{}}
123   template<typename T> int g(T, int); // expected-note +{{}}
124 
125   int k1 = f(&f); // expected-error {{no match}}
126   int k2 = f(&f<int>);
127   int k3 = f(&g<int>); // expected-error {{no match}}
128 
h()129   void h() {
130     (void)&f; // expected-error {{address of overloaded function 'f' cannot be cast to type 'void'}}
131     (void)&f<int>;
132     (void)&g<int>; // expected-error {{address of overloaded function 'g' cannot be cast to type 'void'}}
133 
134     &f; // expected-error {{reference to overloaded function could not be resolved}}
135     &f<int>; // expected-warning {{unused}}
136     &g<int>; // expected-error {{reference to overloaded function could not be resolved}}
137   }
138 
139   struct S {
140     template<typename T> static int f(T);
141     template<typename T> static int g(T);
142     template<typename T> static int g(T, int);
143   } s;
144 
145   int k4 = f(&s.f); // expected-error {{non-constant pointer to member}}
146   int k5 = f(&s.f<int>);
147   int k6 = f(&s.g<int>); // expected-error {{non-constant pointer to member}}
148 
i()149   void i() {
150     (void)&s.f; // expected-error {{non-constant pointer to member}}
151     (void)&s.f<int>;
152     (void)&s.g<int>; // expected-error {{non-constant pointer to member}}
153 
154     &s.f; // expected-error {{non-constant pointer to member}}
155     &s.f<int>; // expected-warning {{unused}}
156     &s.g<int>; // expected-error {{non-constant pointer to member}}
157   }
158 
159   struct T {
160     template<typename T> int f(T);
161     template<typename T> int g(T);
162     template<typename T> int g(T, int);
163   } t;
164 
165   int k7 = f(&s.f); // expected-error {{non-constant pointer to member}}
166   int k8 = f(&s.f<int>);
167   int k9 = f(&s.g<int>); // expected-error {{non-constant pointer to member}}
168 
j()169   void j() {
170     (void)&s.f; // expected-error {{non-constant pointer to member}}
171     (void)&s.f<int>;
172     (void)&s.g<int>; // expected-error {{non-constant pointer to member}}
173 
174     &s.f; // expected-error {{non-constant pointer to member}}
175     &s.f<int>; // expected-warning {{unused}}
176     &s.g<int>; // expected-error {{non-constant pointer to member}}
177   }
178 
179 #if __cplusplus >= 201103L
180   // Special case kicks in only if a template argument list is specified.
181   template<typename T=int> void with_default(); // expected-note +{{}}
182   int k10 = f(&with_default); // expected-error {{no matching function}}
183   int k11 = f(&with_default<>);
k()184   void k() {
185     (void)&with_default; // expected-error {{overloaded function}}
186     (void)&with_default<>;
187     &with_default; // expected-error {{overloaded function}}
188     &with_default<>; // expected-warning {{unused}}
189   }
190 #endif
191 }
192 
193 namespace dr116 { // dr116: yes
194   template<int> struct A {};
f(A<N>)195   template<int N> void f(A<N>) {} // expected-note {{previous}}
f(A<M>)196   template<int M> void f(A<M>) {} // expected-error {{redefinition}}
f(A<sizeof (T)>)197   template<typename T> void f(A<sizeof(T)>) {} // expected-note {{previous}}
f(A<sizeof (U)>)198   template<typename U> void f(A<sizeof(U)>) {} // expected-error {{redefinition}}
199 }
200 
201 // dr117: na
202 // dr118 FIXME: add codegen test
203 // dr119: na
204 // dr120: na
205 
206 namespace dr121 { // dr121: yes
207   struct X {
208     template<typename T> struct Y {};
209   };
210   template<typename T> struct Z {
211     X::Y<T> x;
212     T::Y<T> y; // expected-error +{{}}
213   };
214   Z<X> z;
215 }
216 
217 namespace dr122 { // dr122: yes
218   template<typename T> void f();
g()219   void g() { f<int>(); }
220 }
221 
222 // dr123: na
223 // dr124: dup 201
224 
225 // dr125: yes
226 struct dr125_A { struct dr125_B {}; };
227 dr125_A::dr125_B dr125_C();
228 namespace dr125_B { dr125_A dr125_C(); }
229 namespace dr125 {
230   struct X {
231     friend dr125_A::dr125_B (::dr125_C)(); // ok
232     friend dr125_A (::dr125_B::dr125_C)(); // ok
233     friend dr125_A::dr125_B::dr125_C(); // expected-error {{requires a type specifier}}
234   };
235 }
236 
237 namespace dr126 { // dr126: no
238   struct C {};
239   struct D : C {};
240   struct E : private C { friend class A; friend class B; };
241   struct F : protected C {};
242   struct G : C {};
243   struct H : D, G {};
244 
245   struct A {
246     virtual void cp() throw(C*);
247     virtual void dp() throw(C*);
248     virtual void ep() throw(C*); // expected-note {{overridden}}
249     virtual void fp() throw(C*); // expected-note {{overridden}}
250     virtual void gp() throw(C*);
251     virtual void hp() throw(C*); // expected-note {{overridden}}
252 
253     virtual void cr() throw(C&);
254     virtual void dr() throw(C&);
255     virtual void er() throw(C&); // expected-note {{overridden}}
256     virtual void fr() throw(C&); // expected-note {{overridden}}
257     virtual void gr() throw(C&);
258     virtual void hr() throw(C&); // expected-note {{overridden}}
259 
260     virtual void pv() throw(void*); // expected-note {{overridden}}
261 
262 #if __cplusplus >= 201103L
263     virtual void np() throw(C*); // expected-note {{overridden}}
264     virtual void npm() throw(int C::*); // expected-note {{overridden}}
265     virtual void nr() throw(C&); // expected-note {{overridden}}
266 #endif
267 
268     virtual void ref1() throw(C *const&);
269     virtual void ref2() throw(C *);
270 
271     virtual void v() throw(int);
272     virtual void w() throw(const int);
273     virtual void x() throw(int*);
274     virtual void y() throw(const int*);
275     virtual void z() throw(int); // expected-note {{overridden}}
276   };
277   struct B : A {
278     virtual void cp() throw(C*);
279     virtual void dp() throw(D*);
280     virtual void ep() throw(E*); // expected-error {{more lax}}
281     virtual void fp() throw(F*); // expected-error {{more lax}}
282     virtual void gp() throw(G*);
283     virtual void hp() throw(H*); // expected-error {{more lax}}
284 
285     virtual void cr() throw(C&);
286     virtual void dr() throw(D&);
287     virtual void er() throw(E&); // expected-error {{more lax}}
288     virtual void fr() throw(F&); // expected-error {{more lax}}
289     virtual void gr() throw(G&);
290     virtual void hr() throw(H&); // expected-error {{more lax}}
291 
292     virtual void pv() throw(C*); // expected-error {{more lax}} FIXME: This is valid.
293 
294 #if __cplusplus >= 201103L
295     using nullptr_t = decltype(nullptr);
296     virtual void np() throw(nullptr_t*); // expected-error {{more lax}} FIXME: This is valid.
297     virtual void npm() throw(nullptr_t*); // expected-error {{more lax}} FIXME: This is valid.
298     virtual void nr() throw(nullptr_t&); // expected-error {{more lax}} This is not.
299 #endif
300 
301     virtual void ref1() throw(D *const &);
302     virtual void ref2() throw(D *);
303 
304     virtual void v() throw(const int);
305     virtual void w() throw(int);
306     virtual void x() throw(const int*); // FIXME: 'const int*' is not allowed by A::h.
307     virtual void y() throw(int*); // ok
308     virtual void z() throw(long); // expected-error {{more lax}}
309   };
310 }
311 
312 namespace dr127 { // dr127: yes
313   __extension__ typedef __decltype(sizeof(0)) size_t;
314   template<typename T> struct A {
315     A() throw(int);
316     void *operator new(size_t, const char * = 0);
operator deletedr127::A317     void operator delete(void *, const char *) { T::error; } // expected-error 2{{no members}}
operator deletedr127::A318     void operator delete(void *) { T::error; }
319   };
320   A<void> *p = new A<void>; // expected-note {{instantiat}}
321   A<int> *q = new ("") A<int>; // expected-note {{instantiat}}
322 }
323 
324 namespace dr128 { // dr128: yes
325   enum E1 { e1 } x = e1;
326   enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1);
327 }
328 
329 // dr129: dup 616
330 // dr130: na
331 
332 namespace dr131 { // dr131: yes
333   const char *a_with_\u0e8c = "\u0e8c";
334   const char *b_with_\u0e8d = "\u0e8d";
335   const char *c_with_\u0e8e = "\u0e8e";
336 #if __cplusplus < 201103L
337   // expected-error@-4 {{expected ';'}} expected-error@-2 {{expected ';'}}
338 #endif
339 }
340 
341 namespace dr132 { // dr132: no
f()342   void f() {
343     extern struct {} x; // ok
344     extern struct S {} y; // FIXME: This is invalid.
345   }
346   static enum { E } e;
347 }
348 
349 // dr133: dup 87
350 // dr134: na
351 
352 namespace dr135 { // dr135: yes
353   struct A {
fdr135::A354     A f(A a) { return a; }
g(A a)355     friend A g(A a) { return a; }
hdr135::A356     static A h(A a) { return a; }
357   };
358 }
359 
360 namespace dr136 { // dr136: 3.4
361   void f(int, int, int = 0); // expected-note {{previous declaration is here}}
362   void g(int, int, int); // expected-note {{previous declaration is here}}
363   struct A {
364     friend void f(int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
365     friend void g(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
366     friend void h(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be a definition}}
i(int,int,int=0)367     friend void i(int, int, int = 0) {} // expected-note {{previous declaration is here}}
j(int,int,int=0)368     friend void j(int, int, int = 0) {}
369     operator int();
370   };
371   void i(int, int, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
q()372   void q() {
373     j(A(), A()); // ok, has default argument
374   }
375   extern "C" void k(int, int, int, int); // expected-note {{previous declaration is here}}
376   namespace NSA {
377   struct A {
378     friend void dr136::k(int, int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}} \
379                                                   // expected-note {{previous declaration is here}}
380   };
381   }
382   namespace NSB {
383   struct A {
384     friend void dr136::k(int, int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
385   };
386   }
387   struct B {
388     void f(int); // expected-note {{previous declaration is here}}
389   };
390   struct C {
391     friend void B::f(int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
392   };
393 }
394 
395 namespace dr137 { // dr137: yes
396   extern void *p;
397   extern const void *cp;
398   extern volatile void *vp;
399   extern const volatile void *cvp;
400   int *q = static_cast<int*>(p);
401   int *qc = static_cast<int*>(cp); // expected-error {{casts away qualifiers}}
402   int *qv = static_cast<int*>(vp); // expected-error {{casts away qualifiers}}
403   int *qcv = static_cast<int*>(cvp); // expected-error {{casts away qualifiers}}
404   const int *cq = static_cast<const int*>(p);
405   const int *cqc = static_cast<const int*>(cp);
406   const int *cqv = static_cast<const int*>(vp); // expected-error {{casts away qualifiers}}
407   const int *cqcv = static_cast<const int*>(cvp); // expected-error {{casts away qualifiers}}
408   const volatile int *cvq = static_cast<const volatile int*>(p);
409   const volatile int *cvqc = static_cast<const volatile int*>(cp);
410   const volatile int *cvqv = static_cast<const volatile int*>(vp);
411   const volatile int *cvqcv = static_cast<const volatile int*>(cvp);
412 }
413 
414 namespace dr139 { // dr139: yes
415   namespace example1 {
416     typedef int f; // expected-note {{previous}}
417     struct A {
418       friend void f(A &); // expected-error {{different kind of symbol}}
419     };
420   }
421 
422   namespace example2 {
423     typedef int f;
424     namespace N {
425       struct A {
426         friend void f(A &);
427         operator int();
gdr139::example2::N::A428         void g(A a) { int i = f(a); } // ok, f is typedef not friend function
429       };
430     }
431   }
432 }
433 
434 namespace dr140 { // dr140: yes
f(int * const)435   void f(int *const) {} // expected-note {{previous}}
f(int[3])436   void f(int[3]) {} // expected-error {{redefinition}}
437   void g(const int);
g(int n)438   void g(int n) { n = 2; }
439 }
440 
441 namespace dr141 { // dr141: yes
442   template<typename T> void f();
443   template<typename T> struct S { int n; };
444   struct A : S<int> {
445     template<typename T> void f();
446     template<typename T> struct S {};
447   } a;
448   struct B : S<int> {} b;
g()449   void g() {
450     a.f<int>();
451     (void)a.S<int>::n; // expected-error {{no member named 'n'}}
452 #if __cplusplus < 201103L
453     // expected-error@-2 {{ambiguous}}
454     // expected-note@-11 {{lookup from the current scope}}
455     // expected-note@-9 {{lookup in the object type}}
456 #endif
457     b.f<int>(); // expected-error {{no member}} expected-error +{{}}
458     (void)b.S<int>::n;
459   }
460   template<typename T> struct C {
461     T t;
gdr141::C462     void g() {
463       t.f<int>(); // expected-error {{use 'template'}}
464     }
hdr141::C465     void h() {
466       (void)t.S<int>::n; // ok
467     }
idr141::C468     void i() {
469       (void)t.S<int>(); // ok!
470     }
471   };
h()472   void h() { C<B>().h(); } // ok
473   struct X {
474     template<typename T> void S();
475   };
i()476   void i() { C<X>().i(); } // ok!!
477 }
478 
479 namespace dr142 { // dr142: yes
480   class B { // expected-note +{{here}}
481   public:
482     int mi; // expected-note +{{here}}
483     static int si; // expected-note +{{here}}
484   };
485   class D : private B { // expected-note +{{here}}
486   };
487   class DD : public D {
488     void f();
489   };
f()490   void DD::f() {
491     mi = 3; // expected-error {{private base class}} expected-error {{private member}}
492     si = 3; // expected-error {{private member}}
493     B b_old; // expected-error {{private member}}
494     dr142::B b;
495     b.mi = 3;
496     b.si = 3;
497     B::si = 3; // expected-error {{private member}}
498     dr142::B::si = 3;
499     B *bp1_old = this; // expected-error {{private member}} expected-error {{private base class}}
500     dr142::B *bp1 = this; // expected-error {{private base class}}
501     B *bp2_old = (B*)this; // expected-error 2{{private member}}
502     dr142::B *bp2 = (dr142::B*)this;
503     bp2->mi = 3;
504   }
505 }
506 
507 namespace dr143 { // dr143: yes
508   namespace A { struct X; }
509   namespace B { void f(A::X); }
510   namespace A {
511     struct X { friend void B::f(X); };
512   }
g(A::X x)513   void g(A::X x) {
514     f(x); // expected-error {{undeclared identifier 'f'}}
515   }
516 }
517 
518 namespace dr145 { // dr145: yes
f(bool b)519   void f(bool b) {
520     ++b; // expected-warning {{deprecated}}
521     b++; // expected-warning {{deprecated}}
522   }
523 }
524 
525 namespace dr147 { // dr147: no
526   namespace example1 {
527     template<typename> struct A {
528       template<typename T> A(T);
529     };
530     // FIXME: This appears to be valid, and EDG and G++ accept.
A(int)531     template<> template<> A<int>::A<int>(int) {} // expected-error {{out-of-line constructor for 'A' cannot have template arguments}}
532   }
533   namespace example2 {
534     struct A { A(); };
535     struct B : A { B(); };
536     A::A a1; // expected-error {{is a constructor}}
537     B::A a2;
538   }
539   namespace example3 {
540     template<typename> struct A {
541       template<typename T> A(T);
542       static A a;
543     };
544     template<> A<int>::A<int>(A<int>::a); // expected-error {{is a constructor}}
545   }
546 }
547 
548 namespace dr148 { // dr148: yes
549   struct A { int A::*p; };
550   int check1[__is_pod(int(A::*)) ? 1 : -1];
551   int check2[__is_pod(A) ? 1 : -1];
552 }
553 
554 // dr149: na
555