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