dr1xx.cpp revision a4de17562d13d7a8188108243c4cfbd52f33229a
1// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5
6namespace dr100 { // dr100: yes
7  template<const char *> struct A {}; // expected-note 0-1{{declared here}}
8  template<const char (&)[4]> struct B {}; // expected-note 0-1{{declared here}}
9  A<"foo"> a; // expected-error {{does not refer to any declaration}}
10  B<"bar"> b; // expected-error {{does not refer to any declaration}}
11}
12
13namespace dr101 { // dr101: 3.5
14  extern "C" void dr101_f();
15  typedef unsigned size_t;
16  namespace X {
17    extern "C" void dr101_f();
18    typedef unsigned size_t;
19  }
20  using X::dr101_f;
21  using X::size_t;
22  extern "C" void dr101_f();
23  typedef unsigned size_t;
24}
25
26namespace dr102 { // dr102: yes
27  namespace A {
28    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}}
29  }
30  namespace B {
31    struct S {};
32  }
33  B::S operator+(B::S, B::S); // expected-note {{should be declared prior to the call site or in namespace 'dr102::B'}}
34  template B::S A::f(B::S, B::S); // expected-note {{in instantiation of}}
35}
36
37// dr103: na
38// dr104 FIXME: add codegen test
39// dr105: na
40
41namespace dr106 { // dr106: sup 540
42  typedef int &r1;
43  typedef r1 &r1;
44  typedef const r1 r1; // expected-warning {{has no effect}}
45  typedef const r1 &r1; // expected-warning {{has no effect}}
46
47  typedef const int &r2;
48  typedef r2 &r2;
49  typedef const r2 r2; // expected-warning {{has no effect}}
50  typedef const r2 &r2; // expected-warning {{has no effect}}
51}
52
53namespace dr107 { // dr107: yes
54  struct S {};
55  extern "C" S operator+(S, S) { return S(); }
56}
57
58namespace dr108 { // dr108: yes
59  template<typename T> struct A {
60    struct B { typedef int X; };
61    B::X x; // expected-error {{missing 'typename'}}
62    struct C : B { X x; }; // expected-error {{unknown type name}}
63  };
64  template<> struct A<int>::B { int X; };
65}
66
67namespace dr109 { // dr109: yes
68  struct A { template<typename T> void f(T); };
69  template<typename T> struct B : T {
70    using T::template f; // expected-error {{using declaration cannot refer to a template}}
71    void g() { this->f<int>(123); } // expected-error {{use 'template'}}
72  };
73}
74
75namespace dr111 { // dr111: dup 535
76  struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); };
77  struct B : A { B(); }; // expected-note +{{would lose const qualifier}} expected-note {{requires 0 arguments}}
78  const B b1;
79  B b2(b1); // expected-error {{no matching constructor}}
80}
81
82namespace dr112 { // dr112: yes
83  struct T { int n; };
84  typedef T Arr[1];
85
86  const T a1[1] = {};
87  volatile T a2[1] = {};
88  const Arr a3 = {};
89  volatile Arr a4 = {};
90  template<const volatile T*> struct X {};
91  X<a1> x1;
92  X<a2> x2;
93  X<a3> x3;
94  X<a4> x4;
95#if __cplusplus < 201103L
96  // expected-error@-5 {{internal linkage}} expected-note@-10 {{here}}
97  // expected-error@-4 {{internal linkage}} expected-note@-9 {{here}}
98#else
99  // FIXME: Test this somehow.
100#endif
101}
102
103namespace dr113 { // dr113: yes
104  extern void (*p)();
105  void f() {
106    no_such_function(); // expected-error {{undeclared}}
107    p();
108  }
109  void g();
110  void (*p)() = &g;
111}
112
113namespace dr114 { // dr114: yes
114  struct A {
115    virtual void f(int) = 0; // expected-note {{unimplemented}}
116  };
117  struct B : A {
118    template<typename T> void f(T);
119    void g() { f(0); }
120  } b; // expected-error {{abstract}}
121}
122
123namespace dr115 { // dr115: yes
124  template<typename T> int f(T); // expected-note +{{}}
125  template<typename T> int g(T); // expected-note +{{}}
126  template<typename T> int g(T, int); // expected-note +{{}}
127
128  int k1 = f(&f); // expected-error {{no match}}
129  int k2 = f(&f<int>);
130  int k3 = f(&g<int>); // expected-error {{no match}}
131
132  void h() {
133    (void)&f; // expected-error {{address of overloaded function 'f' cannot be cast to type 'void'}}
134    (void)&f<int>;
135    (void)&g<int>; // expected-error {{address of overloaded function 'g' cannot be cast to type 'void'}}
136
137    &f; // expected-error {{reference to overloaded function could not be resolved}}
138    &f<int>; // expected-warning {{unused}}
139    &g<int>; // expected-error {{reference to overloaded function could not be resolved}}
140  }
141
142  struct S {
143    template<typename T> static int f(T);
144    template<typename T> static int g(T);
145    template<typename T> static int g(T, int);
146  } s;
147
148  int k4 = f(&s.f); // expected-error {{non-constant pointer to member}}
149  int k5 = f(&s.f<int>);
150  int k6 = f(&s.g<int>); // expected-error {{non-constant pointer to member}}
151
152  void i() {
153    (void)&s.f; // expected-error {{non-constant pointer to member}}
154    (void)&s.f<int>;
155    (void)&s.g<int>; // expected-error {{non-constant pointer to member}}
156
157    &s.f; // expected-error {{non-constant pointer to member}}
158    &s.f<int>; // expected-warning {{unused}}
159    &s.g<int>; // expected-error {{non-constant pointer to member}}
160  }
161
162  struct T {
163    template<typename T> int f(T);
164    template<typename T> int g(T);
165    template<typename T> int g(T, int);
166  } t;
167
168  int k7 = f(&s.f); // expected-error {{non-constant pointer to member}}
169  int k8 = f(&s.f<int>);
170  int k9 = f(&s.g<int>); // expected-error {{non-constant pointer to member}}
171
172  void j() {
173    (void)&s.f; // expected-error {{non-constant pointer to member}}
174    (void)&s.f<int>;
175    (void)&s.g<int>; // expected-error {{non-constant pointer to member}}
176
177    &s.f; // expected-error {{non-constant pointer to member}}
178    &s.f<int>; // expected-warning {{unused}}
179    &s.g<int>; // expected-error {{non-constant pointer to member}}
180  }
181
182#if __cplusplus >= 201103L
183  // Special case kicks in only if a template argument list is specified.
184  template<typename T=int> void with_default(); // expected-note +{{}}
185  int k10 = f(&with_default); // expected-error {{no matching function}}
186  int k11 = f(&with_default<>);
187  void k() {
188    (void)&with_default; // expected-error {{overloaded function}}
189    (void)&with_default<>;
190    &with_default; // expected-error {{overloaded function}}
191    &with_default<>; // expected-warning {{unused}}
192  }
193#endif
194}
195
196namespace dr116 { // dr116: yes
197  template<int> struct A {};
198  template<int N> void f(A<N>) {} // expected-note {{previous}}
199  template<int M> void f(A<M>) {} // expected-error {{redefinition}}
200  template<typename T> void f(A<sizeof(T)>) {} // expected-note {{previous}}
201  template<typename U> void f(A<sizeof(U)>) {} // expected-error {{redefinition}}
202}
203
204// dr117: na
205// dr118 FIXME: add codegen test
206// dr119: na
207// dr120: na
208
209namespace dr121 { // dr121: yes
210  struct X {
211    template<typename T> struct Y {};
212  };
213  template<typename T> struct Z {
214    X::Y<T> x;
215    T::Y<T> y; // expected-error +{{}}
216  };
217  Z<X> z;
218}
219
220namespace dr122 { // dr122: yes
221  template<typename T> void f();
222  void g() { f<int>(); }
223}
224
225// dr123: na
226// dr124: dup 201
227
228// dr125: yes
229struct dr125_A { struct dr125_B {}; }; // expected-note {{here}}
230dr125_A::dr125_B dr125_C();
231namespace dr125_B { dr125_A dr125_C(); }
232namespace dr125 {
233  struct X {
234    friend dr125_A::dr125_B (::dr125_C)(); // ok
235    friend dr125_A (::dr125_B::dr125_C)(); // ok
236    friend dr125_A::dr125_B::dr125_C(); // expected-error {{did you mean the constructor name 'dr125_B'?}}
237    // expected-error@-1 {{missing exception specification}}
238#if __cplusplus >= 201103L
239    // expected-error@-3 {{follows constexpr declaration}} expected-note@-10 {{here}}
240#endif
241  };
242}
243
244namespace dr126 { // dr126: no
245  struct C {};
246  struct D : C {};
247  struct E : private C { friend class A; friend class B; };
248  struct F : protected C {};
249  struct G : C {};
250  struct H : D, G {};
251
252  struct A {
253    virtual void cp() throw(C*);
254    virtual void dp() throw(C*);
255    virtual void ep() throw(C*); // expected-note {{overridden}}
256    virtual void fp() throw(C*); // expected-note {{overridden}}
257    virtual void gp() throw(C*);
258    virtual void hp() throw(C*); // expected-note {{overridden}}
259
260    virtual void cr() throw(C&);
261    virtual void dr() throw(C&);
262    virtual void er() throw(C&); // expected-note {{overridden}}
263    virtual void fr() throw(C&); // expected-note {{overridden}}
264    virtual void gr() throw(C&);
265    virtual void hr() throw(C&); // expected-note {{overridden}}
266
267    virtual void pv() throw(void*); // expected-note {{overridden}}
268
269#if __cplusplus >= 201103L
270    virtual void np() throw(C*); // expected-note {{overridden}}
271    virtual void npm() throw(int C::*); // expected-note {{overridden}}
272    virtual void nr() throw(C&); // expected-note {{overridden}}
273#endif
274
275    virtual void ref1() throw(C *const&);
276    virtual void ref2() throw(C *);
277
278    virtual void v() throw(int);
279    virtual void w() throw(const int);
280    virtual void x() throw(int*);
281    virtual void y() throw(const int*);
282    virtual void z() throw(int); // expected-note {{overridden}}
283  };
284  struct B : A {
285    virtual void cp() throw(C*);
286    virtual void dp() throw(D*);
287    virtual void ep() throw(E*); // expected-error {{more lax}}
288    virtual void fp() throw(F*); // expected-error {{more lax}}
289    virtual void gp() throw(G*);
290    virtual void hp() throw(H*); // expected-error {{more lax}}
291
292    virtual void cr() throw(C&);
293    virtual void dr() throw(D&);
294    virtual void er() throw(E&); // expected-error {{more lax}}
295    virtual void fr() throw(F&); // expected-error {{more lax}}
296    virtual void gr() throw(G&);
297    virtual void hr() throw(H&); // expected-error {{more lax}}
298
299    virtual void pv() throw(C*); // expected-error {{more lax}} FIXME: This is valid.
300
301#if __cplusplus >= 201103L
302    using nullptr_t = decltype(nullptr);
303    virtual void np() throw(nullptr_t*); // expected-error {{more lax}} FIXME: This is valid.
304    virtual void npm() throw(nullptr_t*); // expected-error {{more lax}} FIXME: This is valid.
305    virtual void nr() throw(nullptr_t&); // expected-error {{more lax}} This is not.
306#endif
307
308    virtual void ref1() throw(D *const &);
309    virtual void ref2() throw(D *);
310
311    virtual void v() throw(const int);
312    virtual void w() throw(int);
313    virtual void x() throw(const int*); // FIXME: 'const int*' is not allowed by A::h.
314    virtual void y() throw(int*); // ok
315    virtual void z() throw(long); // expected-error {{more lax}}
316  };
317}
318
319namespace dr127 { // dr127: yes
320  __extension__ typedef __decltype(sizeof(0)) size_t;
321  template<typename T> struct A {
322    A() throw(int);
323    void *operator new(size_t, const char * = 0);
324    void operator delete(void *, const char *) { T::error; } // expected-error 2{{no members}}
325    void operator delete(void *) { T::error; }
326  };
327  A<void> *p = new A<void>; // expected-note {{instantiat}}
328  A<int> *q = new ("") A<int>; // expected-note {{instantiat}}
329}
330
331namespace dr128 { // dr128: yes
332  enum E1 { e1 } x = e1;
333  enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1);
334}
335
336// dr129: dup 616
337// dr130: na
338
339namespace dr131 { // dr131: yes
340  const char *a_with_\u0e8c = "\u0e8c";
341  const char *b_with_\u0e8d = "\u0e8d";
342  const char *c_with_\u0e8e = "\u0e8e";
343#if __cplusplus < 201103L
344  // expected-error@-4 {{expected ';'}} expected-error@-2 {{expected ';'}}
345#endif
346}
347
348namespace dr132 { // dr132: no
349  void f() {
350    extern struct {} x; // ok
351    extern struct S {} y; // FIXME: This is invalid.
352  }
353  static enum { E } e;
354}
355
356// dr133: dup 87
357// dr134: na
358
359namespace dr135 { // dr135: yes
360  struct A {
361    A f(A a) { return a; }
362    friend A g(A a) { return a; }
363    static A h(A a) { return a; }
364  };
365}
366
367namespace dr136 { // dr136: 3.4
368  void f(int, int, int = 0); // expected-note {{previous declaration is here}}
369  void g(int, int, int); // expected-note {{previous declaration is here}}
370  struct A {
371    friend void f(int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
372    friend void g(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
373    friend void h(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be a definition}}
374    friend void i(int, int, int = 0) {} // expected-note {{previous declaration is here}}
375    friend void j(int, int, int = 0) {}
376    operator int();
377  };
378  void i(int, int, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
379  void q() {
380    j(A(), A()); // ok, has default argument
381  }
382  extern "C" void k(int, int, int, int); // expected-note {{previous declaration is here}}
383  namespace NSA {
384  struct A {
385    friend void dr136::k(int, int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}} \
386                                                  // expected-note {{previous declaration is here}}
387  };
388  }
389  namespace NSB {
390  struct A {
391    friend void dr136::k(int, int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
392  };
393  }
394  struct B {
395    void f(int); // expected-note {{previous declaration is here}}
396  };
397  struct C {
398    friend void B::f(int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
399  };
400}
401
402namespace dr137 { // dr137: yes
403  extern void *p;
404  extern const void *cp;
405  extern volatile void *vp;
406  extern const volatile void *cvp;
407  int *q = static_cast<int*>(p);
408  int *qc = static_cast<int*>(cp); // expected-error {{casts away qualifiers}}
409  int *qv = static_cast<int*>(vp); // expected-error {{casts away qualifiers}}
410  int *qcv = static_cast<int*>(cvp); // expected-error {{casts away qualifiers}}
411  const int *cq = static_cast<const int*>(p);
412  const int *cqc = static_cast<const int*>(cp);
413  const int *cqv = static_cast<const int*>(vp); // expected-error {{casts away qualifiers}}
414  const int *cqcv = static_cast<const int*>(cvp); // expected-error {{casts away qualifiers}}
415  const volatile int *cvq = static_cast<const volatile int*>(p);
416  const volatile int *cvqc = static_cast<const volatile int*>(cp);
417  const volatile int *cvqv = static_cast<const volatile int*>(vp);
418  const volatile int *cvqcv = static_cast<const volatile int*>(cvp);
419}
420
421namespace dr139 { // dr139: yes
422  namespace example1 {
423    typedef int f; // expected-note {{previous}}
424    struct A {
425      friend void f(A &); // expected-error {{different kind of symbol}}
426    };
427  }
428
429  namespace example2 {
430    typedef int f;
431    namespace N {
432      struct A {
433        friend void f(A &);
434        operator int();
435        void g(A a) { int i = f(a); } // ok, f is typedef not friend function
436      };
437    }
438  }
439}
440
441namespace dr140 { // dr140: yes
442  void f(int *const) {} // expected-note {{previous}}
443  void f(int[3]) {} // expected-error {{redefinition}}
444  void g(const int);
445  void g(int n) { n = 2; }
446}
447
448namespace dr141 { // dr141: yes
449  template<typename T> void f();
450  template<typename T> struct S { int n; };
451  struct A : S<int> {
452    template<typename T> void f();
453    template<typename T> struct S {};
454  } a;
455  struct B : S<int> {} b;
456  void g() {
457    a.f<int>();
458    (void)a.S<int>::n; // expected-error {{no member named 'n'}}
459#if __cplusplus < 201103L
460    // expected-error@-2 {{ambiguous}}
461    // expected-note@-11 {{lookup from the current scope}}
462    // expected-note@-9 {{lookup in the object type}}
463#endif
464    b.f<int>(); // expected-error {{no member}} expected-error +{{}}
465    (void)b.S<int>::n;
466  }
467  template<typename T> struct C {
468    T t;
469    void g() {
470      t.f<int>(); // expected-error {{use 'template'}}
471    }
472    void h() {
473      (void)t.S<int>::n; // ok
474    }
475    void i() {
476      (void)t.S<int>(); // ok!
477    }
478  };
479  void h() { C<B>().h(); } // ok
480  struct X {
481    template<typename T> void S();
482  };
483  void i() { C<X>().i(); } // ok!!
484}
485
486namespace dr142 { // dr142: yes
487  class B { // expected-note +{{here}}
488  public:
489    int mi; // expected-note +{{here}}
490    static int si; // expected-note +{{here}}
491  };
492  class D : private B { // expected-note +{{here}}
493  };
494  class DD : public D {
495    void f();
496  };
497  void DD::f() {
498    mi = 3; // expected-error {{private base class}} expected-error {{private member}}
499    si = 3; // expected-error {{private member}}
500    B b_old; // expected-error {{private member}}
501    dr142::B b;
502    b.mi = 3;
503    b.si = 3;
504    B::si = 3; // expected-error {{private member}}
505    dr142::B::si = 3;
506    B *bp1_old = this; // expected-error {{private member}} expected-error {{private base class}}
507    dr142::B *bp1 = this; // expected-error {{private base class}}
508    B *bp2_old = (B*)this; // expected-error 2{{private member}}
509    dr142::B *bp2 = (dr142::B*)this;
510    bp2->mi = 3;
511  }
512}
513
514namespace dr143 { // dr143: yes
515  namespace A { struct X; }
516  namespace B { void f(A::X); }
517  namespace A {
518    struct X { friend void B::f(X); };
519  }
520  void g(A::X x) {
521    f(x); // expected-error {{undeclared identifier 'f'}}
522  }
523}
524
525namespace dr145 { // dr145: yes
526  void f(bool b) {
527#if __cplusplus <= 201402L
528    ++b; // expected-warning {{deprecated}}
529    b++; // expected-warning {{deprecated}}
530#else
531    ++b; // expected-error {{increment}}
532    b++; // expected-error {{increment}}
533#endif
534  }
535}
536
537namespace dr147 { // dr147: no
538  namespace example1 {
539    template<typename> struct A {
540      template<typename T> A(T);
541    };
542    // FIXME: This appears to be valid, and EDG and G++ accept.
543    template<> template<> A<int>::A<int>(int) {} // expected-error {{out-of-line constructor for 'A' cannot have template arguments}}
544  }
545  namespace example2 {
546    struct A { A(); };
547    struct B : A { B(); };
548    A::A a1; // expected-error {{is a constructor}}
549    B::A a2;
550  }
551  namespace example3 {
552    template<typename> struct A {
553      template<typename T> A(T);
554      static A a;
555    };
556    template<> A<int>::A<int>(A<int>::a); // expected-error {{is a constructor}}
557  }
558}
559
560namespace dr148 { // dr148: yes
561  struct A { int A::*p; };
562  int check1[__is_pod(int(A::*)) ? 1 : -1];
563  int check2[__is_pod(A) ? 1 : -1];
564}
565
566// dr149: na
567
568namespace dr151 { // dr151: yes
569  struct X {};
570  typedef int X::*p;
571#if __cplusplus < 201103L
572#define fold(x) (__builtin_constant_p(0) ? (x) : (x))
573#else
574#define fold
575#endif
576  int check[fold(p() == 0) ? 1 : -1];
577#undef fold
578}
579
580namespace dr152 { // dr152: yes
581  struct A {
582    A(); // expected-note {{not viable}}
583    explicit A(const A&);
584  };
585  A a1 = A(); // expected-error {{no matching constructor}}
586  A a2((A()));
587}
588
589// dr153: na
590
591namespace dr154 { // dr154: yes
592  union { int a; }; // expected-error {{must be declared 'static'}}
593  namespace {
594    union { int b; };
595  }
596  static union { int c; };
597}
598
599namespace dr155 { // dr155: dup 632
600  struct S { int n; } s = { { 1 } }; // expected-warning {{braces around scalar initializer}}
601}
602
603// dr158 FIXME write codegen test
604
605namespace dr159 { // dr159: 3.5
606  namespace X { void f(); }
607  void f();
608  void dr159::f() {} // expected-warning {{extra qualification}}
609  void dr159::X::f() {}
610}
611
612// dr160: na
613
614namespace dr161 { // dr161: yes
615  class A {
616  protected:
617    struct B { int n; } b; // expected-note 2{{here}}
618    static B bs;
619    void f(); // expected-note {{here}}
620    static void sf();
621  };
622  struct C : A {};
623  struct D : A {
624    void g(C c) {
625      (void)b.n;
626      B b1;
627      C::B b2; // ok, accessible as a member of A
628      (void)&C::b; // expected-error {{protected}}
629      (void)&C::bs;
630      (void)c.b; // expected-error {{protected}}
631      (void)c.bs;
632      f();
633      sf();
634      c.f(); // expected-error {{protected}}
635      c.sf();
636      A::f();
637      D::f();
638      A::sf();
639      C::sf();
640      D::sf();
641    }
642  };
643}
644
645namespace dr162 { // dr162: no
646  struct A {
647    char &f(char);
648    static int &f(int);
649
650    void g() {
651      int &a = (&A::f)(0); // FIXME: expected-error {{could not be resolved}}
652      char &b = (&A::f)('0'); // expected-error {{could not be resolved}}
653    }
654  };
655
656  int &c = (&A::f)(0); // FIXME: expected-error {{could not be resolved}}
657  char &d = (&A::f)('0'); // expected-error {{could not be resolved}}
658}
659
660// dr163: na
661
662namespace dr164 { // dr164: yes
663  void f(int);
664  template <class T> int g(T t) { return f(t); }
665
666  enum E { e };
667  int f(E);
668
669  int k = g(e);
670}
671
672namespace dr165 { // dr165: no
673  namespace N {
674    struct A { friend struct B; };
675    void f() { void g(); }
676  }
677  // FIXME: dr1477 says this is ok, dr165 says it's ill-formed
678  struct N::B {};
679  // FIXME: dr165 says this is ill-formed, but the argument in dr1477 says it's ok
680  void N::g() {}
681}
682
683namespace dr166 { // dr166: yes
684  namespace A { class X; }
685
686  template<typename T> int f(T t) { return t.n; }
687  int g(A::X);
688  template<typename T> int h(T t) { return t.n; } // expected-error {{private}}
689  int i(A::X);
690
691  namespace A {
692    class X {
693      friend int f<X>(X);
694      friend int dr166::g(X);
695      friend int h(X);
696      friend int i(X);
697      int n; // expected-note 2{{here}}
698    };
699
700    int h(X x) { return x.n; }
701    int i(X x) { return x.n; }
702  }
703
704  template int f(A::X);
705  int g(A::X x) { return x.n; }
706  template int h(A::X); // expected-note {{instantiation}}
707  int i(A::X x) { return x.n; } // expected-error {{private}}
708}
709
710// dr167: sup 1012
711
712namespace dr168 { // dr168: no
713  extern "C" typedef int (*p)();
714  extern "C++" typedef int (*q)();
715  struct S {
716    static int f();
717  };
718  p a = &S::f; // FIXME: this should fail.
719  q b = &S::f;
720}
721
722namespace dr169 { // dr169: yes
723  template<typename> struct A { int n; };
724  struct B {
725    template<typename> struct C;
726    template<typename> void f();
727    template<typename> static int n; // expected-error 0-1{{extension}}
728  };
729  struct D : A<int>, B {
730    using A<int>::n;
731    using B::C<int>; // expected-error {{using declaration cannot refer to a template specialization}}
732    using B::f<int>; // expected-error {{using declaration cannot refer to a template specialization}}
733    using B::n<int>; // expected-error {{using declaration cannot refer to a template specialization}}
734  };
735}
736
737namespace { // dr171: yes
738  int dr171a;
739}
740int dr171b; // expected-note {{here}}
741namespace dr171 {
742  extern "C" void dr171a();
743  extern "C" void dr171b(); // expected-error {{conflicts}}
744}
745
746namespace dr172 { // dr172: yes
747  enum { zero };
748  int check1[-1 < zero ? 1 : -1];
749
750  enum { x = -1, y = (unsigned int)-1 };
751  int check2[sizeof(x) > sizeof(int) ? 1 : -1];
752
753  enum { a = (unsigned int)-1 / 2 };
754  int check3a[sizeof(a) == sizeof(int) ? 1 : -1];
755  int check3b[-a < 0 ? 1 : -1];
756
757  enum { b = (unsigned int)-1 / 2 + 1 };
758  int check4a[sizeof(b) == sizeof(unsigned int) ? 1 : -1];
759  int check4b[-b > 0 ? 1 : -1];
760
761  enum { c = (unsigned long)-1 / 2 };
762  int check5a[sizeof(c) == sizeof(long) ? 1 : -1];
763  int check5b[-c < 0 ? 1 : -1];
764
765  enum { d = (unsigned long)-1 / 2 + 1 };
766  int check6a[sizeof(d) == sizeof(unsigned long) ? 1 : -1];
767  int check6b[-d > 0 ? 1 : -1];
768
769  enum { e = (unsigned long long)-1 / 2 }; // expected-error 0-1{{extension}}
770  int check7a[sizeof(e) == sizeof(long) ? 1 : -1]; // expected-error 0-1{{extension}}
771  int check7b[-e < 0 ? 1 : -1];
772
773  enum { f = (unsigned long long)-1 / 2 + 1 }; // expected-error 0-1{{extension}}
774  int check8a[sizeof(f) == sizeof(unsigned long) ? 1 : -1]; // expected-error 0-1{{extension}}
775  int check8b[-f > 0 ? 1 : -1];
776}
777
778namespace dr173 { // dr173: yes
779  int check[('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' &&
780             '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' &&
781             '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9') ? 1 : -1];
782}
783
784// dr174: sup 1012
785
786namespace dr175 { // dr175: yes
787  struct A {}; // expected-note {{here}}
788  struct B : private A {}; // expected-note {{constrained by private inheritance}}
789  struct C : B {
790    A a; // expected-error {{private}}
791    dr175::A b;
792  };
793}
794
795namespace dr176 { // dr176: yes
796  template<typename T> class Y;
797  template<> class Y<int> {
798    void f() {
799      typedef Y A; // expected-note {{here}}
800      typedef Y<char> A; // expected-error {{different types ('Y<char>' vs 'Y<int>')}}
801    }
802  };
803
804  template<typename T> struct Base {}; // expected-note 2{{found}}
805  template<typename T> struct Derived : public Base<T> {
806    void f() {
807      typedef typename Derived::template Base<T> A;
808      typedef typename Derived::Base A;
809    }
810  };
811  template struct Derived<int>;
812
813  template<typename T> struct Derived2 : Base<int>, Base<char> {
814    typename Derived2::Base b; // expected-error {{found in multiple base classes}}
815    typename Derived2::Base<double> d;
816  };
817
818  template<typename T> class X { // expected-note {{here}}
819    X *p1;
820    X<T> *p2;
821    X<int> *p3;
822    dr176::X *p4; // expected-error {{requires template arguments}}
823  };
824}
825
826namespace dr177 { // dr177: yes
827  struct B {};
828  struct A {
829    A(A &); // expected-note {{not viable: expects an l-value}}
830    A(const B &);
831  };
832  B b;
833  A a = b; // expected-error {{no viable constructor copying variable}}
834}
835
836namespace dr178 { // dr178: yes
837  int check[int() == 0 ? 1 : -1];
838#if __cplusplus >= 201103L
839  static_assert(int{} == 0, "");
840  struct S { int a, b; };
841  static_assert(S{1}.b == 0, "");
842  struct T { constexpr T() : n() {} int n; };
843  static_assert(T().n == 0, "");
844  struct U : S { constexpr U() : S() {} };
845  static_assert(U().b == 0, "");
846#endif
847}
848
849namespace dr179 { // dr179: yes
850  void f();
851  int n = &f - &f; // expected-error {{arithmetic on pointers to the function type 'void ()'}}
852}
853
854namespace dr180 { // dr180: yes
855  template<typename T> struct X : T, T::some_base {
856    X() : T::some_type_that_might_be_T(), T::some_base() {}
857    friend class T::some_class;
858    void f() {
859      enum T::some_enum e;
860    }
861  };
862}
863
864namespace dr181 { // dr181: yes
865  namespace X {
866    template <template X<class T> > struct A { }; // expected-error +{{}}
867    template <template X<class T> > void f(A<X>) { } // expected-error +{{}}
868  }
869
870  namespace Y {
871    template <template <class T> class X> struct A { };
872    template <template <class T> class X> void f(A<X>) { }
873  }
874}
875
876namespace dr182 { // dr182: yes
877  template <class T> struct C {
878    void f();
879    void g();
880  };
881
882  template <class T> void C<T>::f() {}
883  template <class T> void C<T>::g() {}
884
885  class A {
886    class B {}; // expected-note {{here}}
887    void f();
888  };
889
890  template void C<A::B>::f();
891  template <> void C<A::B>::g(); // expected-error {{private}}
892
893  void A::f() {
894    C<B> cb;
895    cb.f();
896  }
897}
898
899namespace dr183 { // dr183: sup 382
900  template<typename T> struct A {};
901  template<typename T> struct B {
902    typedef int X;
903  };
904  template<> struct A<int> {
905    typename B<int>::X x;
906  };
907}
908
909namespace dr184 { // dr184: yes
910  template<typename T = float> struct B {};
911
912  template<template<typename TT = float> class T> struct A {
913    void f();
914    void g();
915  };
916
917  template<template<typename TT> class T> void A<T>::f() { // expected-note {{here}}
918    T<> t; // expected-error {{too few template arguments}}
919  }
920
921  template<template<typename TT = char> class T> void A<T>::g() {
922    T<> t;
923    typedef T<> X;
924    typedef T<char> X;
925  }
926
927  void h() { A<B>().g(); }
928}
929
930// dr185 FIXME: add codegen test
931
932namespace dr187 { // dr187: sup 481
933  const int Z = 1;
934  template<int X = Z, int Z = X> struct A;
935  typedef A<> T;
936  typedef A<1, 1> T;
937}
938
939namespace dr188 { // dr188: yes
940  char c[10];
941  int check[sizeof(0, c) == 10 ? 1 : -1];
942}
943
944// dr190 FIXME: add codegen test for tbaa
945
946// dr193 FIXME: add codegen test
947
948namespace dr194 { // dr194: yes
949  struct A {
950    A();
951    void A(); // expected-error {{constructor cannot have a return type}}
952  };
953  struct B {
954    void B(); // expected-error {{constructor cannot have a return type}}
955    B();
956  };
957  struct C {
958    inline explicit C(int) {}
959  };
960}
961
962namespace dr195 { // dr195: yes
963  void f();
964  int *p = (int*)&f; // expected-error 0-1{{extension}}
965  void (*q)() = (void(*)())&p; // expected-error 0-1{{extension}}
966}
967
968namespace dr197 { // dr197: yes
969  char &f(char);
970
971  template <class T> void g(T t) {
972    char &a = f(1);
973    char &b = f(T(1)); // expected-error {{unrelated type 'int'}}
974    char &c = f(t); // expected-error {{unrelated type 'int'}}
975  }
976
977  void f(int);
978
979  enum E { e };
980  int &f(E);
981
982  void h() {
983    g('a');
984    g(2);
985    g(e); // expected-note {{in instantiation of}}
986  }
987}
988
989namespace dr198 { // dr198: yes
990  struct A {
991    int n;
992    struct B {
993      int m[sizeof(n)];
994#if __cplusplus < 201103L
995      // expected-error@-2 {{invalid use of non-static data member}}
996#endif
997      int f() { return n; }
998      // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}}
999    };
1000    struct C;
1001    struct D;
1002  };
1003  struct A::C {
1004    int m[sizeof(n)];
1005#if __cplusplus < 201103L
1006    // expected-error@-2 {{invalid use of non-static data member}}
1007#endif
1008    int f() { return n; }
1009    // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}}
1010  };
1011  struct A::D : A {
1012    int m[sizeof(n)];
1013#if __cplusplus < 201103L
1014    // expected-error@-2 {{invalid use of non-static data member}}
1015#endif
1016    int f() { return n; }
1017  };
1018}
1019
1020// dr199 FIXME: add codegen test
1021