Home | History | Annotate | Download | only in SemaCXX
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
      3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
      4 
      5 // <rdar://problem/8124080>
      6 template<typename _Alloc> class allocator;
      7 template<class _CharT> struct char_traits;
      8 template<typename _CharT, typename _Traits = char_traits<_CharT>,
      9          typename _Alloc = allocator<_CharT> >
     10 class basic_string;
     11 template<typename _CharT, typename _Traits, typename _Alloc>
     12 const typename basic_string<_CharT, _Traits, _Alloc>::size_type
     13 basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_max_size // expected-error{{no member named '_Rep' in 'basic_string<_CharT, _Traits, _Alloc>'}}
     14   = (((npos - sizeof(_Rep_base))/sizeof(_CharT)) - 1) / 4;
     15 
     16 // PR7118
     17 template<typename T>
     18 class Foo {
     19   class Bar;
     20   void f() {
     21     Bar i;
     22   }
     23 };
     24 
     25 // PR7625
     26 template<typename T> struct a : T {
     27  struct x : T {
     28    int aa() { return p; } // expected-error{{use of undeclared identifier 'p'}}
     29  };
     30 };
     31 
     32 // rdar://8605381
     33 namespace rdar8605381 {
     34 struct X {};
     35 
     36 struct Y { // expected-note{{candidate constructor (the implicit copy constructor) not viable}}
     37 #if __cplusplus >= 201103L // C++11 or later
     38 // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable}}
     39 #endif
     40 
     41   Y();
     42 };
     43 
     44 struct {
     45   Y obj;
     46 } objs[] = {
     47   new Y // expected-error{{no viable conversion}}
     48 };
     49 }
     50 
     51 // http://llvm.org/PR8234
     52 namespace PR8234 {
     53 template<typename Signature>
     54 class callback
     55 {
     56 };
     57 
     58 template<typename R , typename ARG_TYPE0>
     59 class callback<R( ARG_TYPE0)>
     60 {
     61     public:
     62         callback() {}
     63 };
     64 
     65 template< typename ARG_TYPE0>
     66 class callback<void( ARG_TYPE0)>
     67 {
     68     public:
     69         callback() {}
     70 };
     71 
     72 void f()
     73 {
     74     callback<void(const int&)> op;
     75 }
     76 }
     77 
     78 namespace PR9007 {
     79   struct bar {
     80     enum xxx {
     81       yyy = sizeof(struct foo*)
     82     };
     83     foo *xxx();
     84   };
     85 }
     86 
     87 namespace PR9026 {
     88   class InfallibleTArray {
     89   };
     90   class Variant;
     91   class CompVariant {
     92     operator const InfallibleTArray&() const;
     93   };
     94   class Variant {
     95     operator const CompVariant&() const;
     96   };
     97   void     Write(const Variant& __v);
     98   void     Write(const InfallibleTArray& __v);
     99   Variant x;
    100   void Write2() {
    101     Write(x);
    102   }
    103 }
    104 
    105 namespace PR10270 {
    106   template<typename T> class C;
    107   template<typename T> void f() {
    108     if (C<T> == 1) // expected-error{{expected unqualified-id}}
    109       return;
    110   }
    111 }
    112 
    113 namespace rdar11806334 {
    114 
    115 class cc_YCbCr;
    116 
    117 class cc_rgb
    118 {
    119  public:
    120   cc_rgb( uint p ); // expected-error {{unknown type name}}
    121   cc_rgb( cc_YCbCr v_in );
    122 };
    123 
    124 class cc_hsl
    125 {
    126  public:
    127   cc_rgb rgb();
    128   cc_YCbCr YCbCr();
    129 };
    130 
    131 class cc_YCbCr
    132 {
    133  public:
    134   cc_YCbCr( const cc_rgb v_in );
    135 };
    136 
    137 cc_YCbCr cc_hsl::YCbCr()
    138 {
    139  cc_YCbCr v_out = cc_YCbCr( rgb());
    140  return v_out;
    141 }
    142 
    143 }
    144 
    145 namespace test1 {
    146   int getString(const int*);
    147   template<int a> class ELFObjectFile  {
    148     const int* sh;
    149     ELFObjectFile() {
    150       switch (*sh) {
    151       }
    152       int SectionName(getString(sh));
    153     }
    154   };
    155 }
    156 
    157 namespace test2 {
    158   struct fltSemantics ;
    159   const fltSemantics &foobar();
    160   void VisitCastExpr(int x) {
    161     switch (x) {
    162     case 42:
    163       const fltSemantics &Sem = foobar();
    164     }
    165   }
    166 }
    167 
    168 namespace test3 {
    169   struct nsCSSRect {
    170   };
    171   static int nsCSSRect::* sides;
    172   nsCSSRect dimenX;
    173   void ParseBoxCornerRadii(int y) {
    174     switch (y) {
    175     }
    176     int& x = dimenX.*sides;
    177   }
    178 }
    179 
    180 namespace pr16964 {
    181   template<typename> struct bs {
    182     bs();
    183     static int* member(); // expected-note{{possible target}}
    184     member();  // expected-error{{C++ requires a type specifier for all declarations}}
    185     static member();  // expected-error{{C++ requires a type specifier for all declarations}}
    186     static int* member(int); // expected-note{{possible target}}
    187   };
    188 
    189   template<typename T> bs<T>::bs() { member; }  // expected-error{{did you mean to call it}}
    190 
    191   bs<int> test() {
    192     return bs<int>(); // expected-note{{in instantiation}}
    193   }
    194 }
    195 
    196 namespace pr12791 {
    197   template<class _Alloc> class allocator {};
    198   template<class _CharT> struct char_traits;
    199   struct input_iterator_tag {};
    200   struct forward_iterator_tag : public input_iterator_tag {};
    201 
    202   template<typename _CharT, typename _Traits, typename _Alloc> struct basic_string {
    203     struct _Alloc_hider : _Alloc { _Alloc_hider(_CharT*, const _Alloc&); };
    204     mutable _Alloc_hider _M_dataplus;
    205     template<class _InputIterator> basic_string(_InputIterator __beg, _InputIterator __end, const _Alloc& __a = _Alloc());
    206     template<class _InIterator> static _CharT* _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, input_iterator_tag);
    207     template<class _FwdIterator> static _CharT* _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, forward_iterator_tag);
    208     static _CharT* _S_construct(size_type __req, _CharT __c, const _Alloc& __a); // expected-error{{unknown type name 'size_type'}}
    209   };
    210 
    211   template<typename _CharT, typename _Traits, typename _Alloc>
    212   template<typename _InputIterator>
    213   basic_string<_CharT, _Traits, _Alloc>:: basic_string(_InputIterator __beg, _InputIterator __end, const _Alloc& __a)
    214   : _M_dataplus(_S_construct(__beg, __end, __a, input_iterator_tag()), __a) {}
    215 
    216   template<typename _CharT, typename _Traits = char_traits<_CharT>, typename _Alloc = allocator<_CharT> > struct basic_stringbuf {
    217     typedef _CharT char_type;
    218     typedef basic_string<char_type, _Traits, _Alloc> __string_type;
    219     __string_type str() const {__string_type((char_type*)0,(char_type*)0);}
    220   };
    221 
    222   template class basic_stringbuf<char>;
    223 }
    224 
    225 namespace pr16989 {
    226   class C {
    227     template <class T>
    228     C tpl_mem(T *) { return }    // expected-error{{expected expression}}
    229     void mem(int *p) {
    230       tpl_mem(p);
    231     }
    232   };
    233   class C2 {
    234     void f();
    235   };
    236   void C2::f() {}
    237 }
    238 
    239 namespace pr20660 {
    240  appendList(int[]...);     // expected-error {{C++ requires a type specifier for all declarations}}
    241  appendList(int[]...) { }  // expected-error {{C++ requires a type specifier for all declarations}}
    242 }
    243 
    244