1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
5 // ---------------------------------------------------------------------
6 // C++ Functional Casts
7 // ---------------------------------------------------------------------
15 template struct ValueInit0
<5>;
18 struct FunctionalCast0
{
24 template struct FunctionalCast0
<5>;
26 struct X
{ // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
27 #if __cplusplus >= 201103L
28 // expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}}
30 X(int, int); // expected-note 3 {{candidate constructor}}
33 template<int N
, int M
>
34 struct BuildTemporary0
{
40 template struct BuildTemporary0
<5, 7>;
42 template<int N
, int M
>
49 template struct Temporaries0
<5, 7>;
51 // Ensure that both the constructor and the destructor are instantiated by
52 // checking for parse errors from each.
53 template<int N
> struct BadX
{
54 BadX() { int a
[-N
]; } // expected-error {{array with a negative size}}
55 ~BadX() { int a
[-N
]; } // expected-error {{array with a negative size}}
60 void f() { (void)BadX
<1>(); } // expected-note 2 {{instantiation}}
62 template struct PR6671
<1>;
64 // ---------------------------------------------------------------------
65 // new/delete expressions
66 // ---------------------------------------------------------------------
73 return new T
; // expected-error{{no matching}}
79 template struct New0
<int>;
80 template struct New0
<Y
>;
81 template struct New0
<X
>; // expected-note{{instantiation}}
83 template<typename T
, typename Arg1
>
85 T
* f(bool x
, Arg1 a1
) {
86 return new T(a1
); // expected-error{{no matching}}
90 template struct New1
<int, float>;
91 template struct New1
<Y
, Y
>;
92 template struct New1
<X
, Y
>; // expected-note{{instantiation}}
94 template<typename T
, typename Arg1
, typename Arg2
>
96 T
* f(bool x
, Arg1 a1
, Arg2 a2
) {
97 return new T(a1
, a2
); // expected-error{{no matching}}
101 template struct New2
<X
, int, float>;
102 template struct New2
<X
, int, int*>; // expected-note{{instantiation}}
103 // FIXME: template struct New2<int, int, float>;
109 void *operator new[](__SIZE_TYPE__
) __attribute__((unavailable
)); // expected-note{{explicitly marked unavailable here}}
113 void* object_creator() {
114 return new C(); // expected-error{{'operator new[]' is unavailable}}
117 template void *object_creator
<New3
[4]>(); // expected-note{{instantiation}}
122 delete t
; // expected-error{{cannot delete}}
123 ::delete [] t
; // expected-error{{cannot delete}}
127 template struct Delete0
<int*>;
128 template struct Delete0
<X
*>;
129 template struct Delete0
<int>; // expected-note{{instantiation}}
148 T
*ptr
= 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
154 new X
<int>[1]; // expected-note{{in instantiation of member function 'PR10480::X<int>::~X' requested here}}
157 template void f
<int>();
160 // ---------------------------------------------------------------------
162 // ---------------------------------------------------------------------
167 throw t
; // expected-error{{incomplete type}}
171 struct Incomplete
; // expected-note 2{{forward}}
173 template struct Throw1
<int>;
174 template struct Throw1
<int*>;
175 template struct Throw1
<Incomplete
*>; // expected-note{{instantiation}}
177 // ---------------------------------------------------------------------
178 // typeid expressions
179 // ---------------------------------------------------------------------
187 const std::type_info
&f(T
* ptr
) {
191 return typeid(T
); // expected-error{{'typeid' of incomplete type 'Incomplete'}}
197 const std::type_info
&f() {
198 return typeid(T
); // expected-error-re 2{{type operand 'void () {{const|&}}' of 'typeid' cannot have '{{const|&}}' qualifier}}
203 virtual void f() = 0;
206 template struct TypeId0
<int>;
207 template struct TypeId0
<Incomplete
>; // expected-note{{instantiation of member function}}
208 template struct TypeId0
<Abstract
>;
209 template struct TypeId1
<void() const>; // expected-note{{instantiation of}}
210 template struct TypeId1
<void() &>; // expected-warning 0-1{{C++11}} expected-note{{instantiation of}}
212 // ---------------------------------------------------------------------
214 // ---------------------------------------------------------------------
217 static const bool value
= __is_pod(T
);
220 static int is_pod0
[is_pod
<X
>::value
? -1 : 1];
221 static int is_pod1
[is_pod
<Y
>::value
? 1 : -1];
223 // ---------------------------------------------------------------------
225 // ---------------------------------------------------------------------
226 template<typename T
, typename Val1
>
230 #if __cplusplus >= 201103L
231 // expected-error@-2 {{type 'float' cannot be narrowed to 'int' in initializer list}}
232 // expected-note@-3 {{insert an explicit cast to silence this issue}}
242 template struct InitList1
<int[1], float>;
243 #if __cplusplus >= 201103L
244 // expected-note@-2 {{instantiation of member function}}
246 template struct InitList1
<APair
, int*>;
248 template<typename T
, typename Val1
, typename Val2
>
250 void f(Val1 val1
, Val2 val2
) {
251 T x
= { val1
, val2
}; // expected-error{{cannot initialize}}
255 template struct InitList2
<APair
, int*, float*>;
256 template struct InitList2
<APair
, int*, double*>; // expected-note{{instantiation}}
258 // ---------------------------------------------------------------------
260 // ---------------------------------------------------------------------
261 template<typename T
, typename Result
>
264 Result result
= t
.m
; // expected-error{{non-const lvalue reference to type}}
272 struct InheritsMemInt
: MemInt
{ };
278 template struct DotMemRef0
<MemInt
, int&>;
279 template struct DotMemRef0
<InheritsMemInt
, int&>;
280 template struct DotMemRef0
<MemIntFunc
, int (*)(int)>;
281 template struct DotMemRef0
<MemInt
, float&>; // expected-note{{instantiation}}
283 template<typename T
, typename Result
>
284 struct ArrowMemRef0
{
286 Result result
= t
->m
; // expected-error 2{{non-const lvalue reference}}
291 struct ArrowWrapper
{
295 template struct ArrowMemRef0
<MemInt
*, int&>;
296 template struct ArrowMemRef0
<InheritsMemInt
*, int&>;
297 template struct ArrowMemRef0
<MemIntFunc
*, int (*)(int)>;
298 template struct ArrowMemRef0
<MemInt
*, float&>; // expected-note{{instantiation}}
300 template struct ArrowMemRef0
<ArrowWrapper
<MemInt
*>, int&>;
301 template struct ArrowMemRef0
<ArrowWrapper
<InheritsMemInt
*>, int&>;
302 template struct ArrowMemRef0
<ArrowWrapper
<MemIntFunc
*>, int (*)(int)>;
303 template struct ArrowMemRef0
<ArrowWrapper
<MemInt
*>, float&>; // expected-note{{instantiation}}
304 template struct ArrowMemRef0
<ArrowWrapper
<ArrowWrapper
<MemInt
*> >, int&>;
306 struct UnresolvedMemRefArray
{
310 UnresolvedMemRefArray Arr
[10];
311 template<typename U
> int UnresolvedMemRefArrayT(U u
) {
314 template int UnresolvedMemRefArrayT
<int>(int);
316 // FIXME: we should be able to return a MemInt without the reference!
317 MemInt
&createMemInt(int);
320 struct NonDepMemberExpr0
{
322 createMemInt(N
).m
= N
;
326 template struct NonDepMemberExpr0
<0>;
328 template<typename T
, typename Result
>
329 struct MemberFuncCall0
{
331 Result result
= t
.f();
341 template struct MemberFuncCall0
<HasMemFunc0
<int&>, const int&>;
343 template<typename Result
>
344 struct ThisMemberFuncCall0
{
349 Result r2
= this->g();
353 template struct ThisMemberFuncCall0
<int&>;
356 struct NonDepMemberCall0
{
357 void foo(HasMemFunc0
<int&> x
) {
358 T result
= x
.f(); // expected-error{{non-const lvalue reference}}
362 template struct NonDepMemberCall0
<int&>;
363 template struct NonDepMemberCall0
<const int&>;
364 template struct NonDepMemberCall0
<float&>; // expected-note{{instantiation}}
368 struct QualifiedDeclRef0
{
370 return is_pod
<X
>::value
; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'const bool'}}
374 template struct QualifiedDeclRef0
<bool>;
375 template struct QualifiedDeclRef0
<int&>; // expected-note{{instantiation}}