1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
3 // ---------------------------------------------------------------------
4 // C++ Functional Casts
5 // ---------------------------------------------------------------------
13 template struct ValueInit0
<5>;
16 struct FunctionalCast0
{
22 template struct FunctionalCast0
<5>;
24 struct X
{ // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
25 X(int, int); // expected-note 3 {{candidate constructor}}
28 template<int N
, int M
>
29 struct BuildTemporary0
{
35 template struct BuildTemporary0
<5, 7>;
37 template<int N
, int M
>
44 template struct Temporaries0
<5, 7>;
46 // Ensure that both the constructor and the destructor are instantiated by
47 // checking for parse errors from each.
48 template<int N
> struct BadX
{
49 BadX() { int a
[-N
]; } // expected-error {{array with a negative size}}
50 ~BadX() { int a
[-N
]; } // expected-error {{array with a negative size}}
55 void f() { (void)BadX
<1>(); } // expected-note 2 {{instantiation}}
57 template struct PR6671
<1>;
59 // ---------------------------------------------------------------------
60 // new/delete expressions
61 // ---------------------------------------------------------------------
68 return new T
; // expected-error{{no matching}}
74 template struct New0
<int>;
75 template struct New0
<Y
>;
76 template struct New0
<X
>; // expected-note{{instantiation}}
78 template<typename T
, typename Arg1
>
80 T
* f(bool x
, Arg1 a1
) {
81 return new T(a1
); // expected-error{{no matching}}
85 template struct New1
<int, float>;
86 template struct New1
<Y
, Y
>;
87 template struct New1
<X
, Y
>; // expected-note{{instantiation}}
89 template<typename T
, typename Arg1
, typename Arg2
>
91 T
* f(bool x
, Arg1 a1
, Arg2 a2
) {
92 return new T(a1
, a2
); // expected-error{{no matching}}
96 template struct New2
<X
, int, float>;
97 template struct New2
<X
, int, int*>; // expected-note{{instantiation}}
98 // FIXME: template struct New2<int, int, float>;
104 void *operator new[](__SIZE_TYPE__
) __attribute__((unavailable
)); // expected-note{{explicitly made unavailable}}
108 void* object_creator() {
109 return new C(); // expected-error{{call to unavailable function 'operator new[]'}}
112 template void *object_creator
<New3
[4]>(); // expected-note{{instantiation}}
117 delete t
; // expected-error{{cannot delete}}
118 ::delete [] t
; // expected-error{{cannot delete}}
122 template struct Delete0
<int*>;
123 template struct Delete0
<X
*>;
124 template struct Delete0
<int>; // expected-note{{instantiation}}
143 T
*ptr
= 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
149 new X
<int>[1]; // expected-note{{in instantiation of member function 'PR10480::X<int>::~X' requested here}}
152 template void f
<int>();
155 // ---------------------------------------------------------------------
157 // ---------------------------------------------------------------------
162 throw t
; // expected-error{{incomplete type}}
166 struct Incomplete
; // expected-note 2{{forward}}
168 template struct Throw1
<int>;
169 template struct Throw1
<int*>;
170 template struct Throw1
<Incomplete
*>; // expected-note{{instantiation}}
172 // ---------------------------------------------------------------------
173 // typeid expressions
174 // ---------------------------------------------------------------------
182 const std::type_info
&f(T
* ptr
) {
186 return typeid(T
); // expected-error{{'typeid' of incomplete type 'Incomplete'}}
191 virtual void f() = 0;
194 template struct TypeId0
<int>;
195 template struct TypeId0
<Incomplete
>; // expected-note{{instantiation of member function}}
196 template struct TypeId0
<Abstract
>;
198 // ---------------------------------------------------------------------
200 // ---------------------------------------------------------------------
203 static const bool value
= __is_pod(T
);
206 static int is_pod0
[is_pod
<X
>::value
? -1 : 1];
207 static int is_pod1
[is_pod
<Y
>::value
? 1 : -1];
209 // ---------------------------------------------------------------------
211 // ---------------------------------------------------------------------
212 template<typename T
, typename Val1
>
224 template struct InitList1
<int[1], float>;
225 template struct InitList1
<APair
, int*>;
227 template<typename T
, typename Val1
, typename Val2
>
229 void f(Val1 val1
, Val2 val2
) {
230 T x
= { val1
, val2
}; // expected-error{{cannot initialize}}
234 template struct InitList2
<APair
, int*, float*>;
235 template struct InitList2
<APair
, int*, double*>; // expected-note{{instantiation}}
237 // ---------------------------------------------------------------------
239 // ---------------------------------------------------------------------
240 template<typename T
, typename Result
>
243 Result result
= t
.m
; // expected-error{{non-const lvalue reference to type}}
251 struct InheritsMemInt
: MemInt
{ };
257 template struct DotMemRef0
<MemInt
, int&>;
258 template struct DotMemRef0
<InheritsMemInt
, int&>;
259 template struct DotMemRef0
<MemIntFunc
, int (*)(int)>;
260 template struct DotMemRef0
<MemInt
, float&>; // expected-note{{instantiation}}
262 template<typename T
, typename Result
>
263 struct ArrowMemRef0
{
265 Result result
= t
->m
; // expected-error 2{{non-const lvalue reference}}
270 struct ArrowWrapper
{
274 template struct ArrowMemRef0
<MemInt
*, int&>;
275 template struct ArrowMemRef0
<InheritsMemInt
*, int&>;
276 template struct ArrowMemRef0
<MemIntFunc
*, int (*)(int)>;
277 template struct ArrowMemRef0
<MemInt
*, float&>; // expected-note{{instantiation}}
279 template struct ArrowMemRef0
<ArrowWrapper
<MemInt
*>, int&>;
280 template struct ArrowMemRef0
<ArrowWrapper
<InheritsMemInt
*>, int&>;
281 template struct ArrowMemRef0
<ArrowWrapper
<MemIntFunc
*>, int (*)(int)>;
282 template struct ArrowMemRef0
<ArrowWrapper
<MemInt
*>, float&>; // expected-note{{instantiation}}
283 template struct ArrowMemRef0
<ArrowWrapper
<ArrowWrapper
<MemInt
*> >, int&>;
285 struct UnresolvedMemRefArray
{
289 UnresolvedMemRefArray Arr
[10];
290 template<typename U
> int UnresolvedMemRefArrayT(U u
) {
293 template int UnresolvedMemRefArrayT
<int>(int);
295 // FIXME: we should be able to return a MemInt without the reference!
296 MemInt
&createMemInt(int);
299 struct NonDepMemberExpr0
{
301 createMemInt(N
).m
= N
;
305 template struct NonDepMemberExpr0
<0>;
307 template<typename T
, typename Result
>
308 struct MemberFuncCall0
{
310 Result result
= t
.f();
320 template struct MemberFuncCall0
<HasMemFunc0
<int&>, const int&>;
322 template<typename Result
>
323 struct ThisMemberFuncCall0
{
328 Result r2
= this->g();
332 template struct ThisMemberFuncCall0
<int&>;
335 struct NonDepMemberCall0
{
336 void foo(HasMemFunc0
<int&> x
) {
337 T result
= x
.f(); // expected-error{{non-const lvalue reference}}
341 template struct NonDepMemberCall0
<int&>;
342 template struct NonDepMemberCall0
<const int&>;
343 template struct NonDepMemberCall0
<float&>; // expected-note{{instantiation}}
347 struct QualifiedDeclRef0
{
349 return is_pod
<X
>::value
; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'const bool'}}
353 template struct QualifiedDeclRef0
<bool>;
354 template struct QualifiedDeclRef0
<int&>; // expected-note{{instantiation}}