2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2009-05-21 05:38:11 +08:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// C++ Functional Casts
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
template<int N>
|
|
|
|
struct ValueInit0 {
|
|
|
|
int f() {
|
|
|
|
return int();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct ValueInit0<5>;
|
|
|
|
|
|
|
|
template<int N>
|
|
|
|
struct FunctionalCast0 {
|
|
|
|
int f() {
|
|
|
|
return int(N);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct FunctionalCast0<5>;
|
|
|
|
|
2010-01-06 17:43:14 +08:00
|
|
|
struct X { // expected-note 3 {{candidate is the implicit copy constructor}}
|
|
|
|
X(int, int); // expected-note 3 {{candidate constructor}}
|
2009-05-21 05:38:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<int N, int M>
|
|
|
|
struct BuildTemporary0 {
|
|
|
|
X f() {
|
|
|
|
return X(N, M);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct BuildTemporary0<5, 7>;
|
2009-05-21 05:51:01 +08:00
|
|
|
|
|
|
|
template<int N, int M>
|
|
|
|
struct Temporaries0 {
|
|
|
|
void f() {
|
|
|
|
(void)X(N, M);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct Temporaries0<5, 7>;
|
2009-05-21 08:00:09 +08:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
2009-05-22 01:21:12 +08:00
|
|
|
// new/delete expressions
|
2009-05-21 08:00:09 +08:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
struct Y { };
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct New0 {
|
|
|
|
T* f(bool x) {
|
|
|
|
if (x)
|
|
|
|
return new T; // expected-error{{no matching}}
|
|
|
|
else
|
|
|
|
return new T();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct New0<int>;
|
|
|
|
template struct New0<Y>;
|
|
|
|
template struct New0<X>; // expected-note{{instantiation}}
|
|
|
|
|
|
|
|
template<typename T, typename Arg1>
|
|
|
|
struct New1 {
|
|
|
|
T* f(bool x, Arg1 a1) {
|
|
|
|
return new T(a1); // expected-error{{no matching}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct New1<int, float>;
|
|
|
|
template struct New1<Y, Y>;
|
|
|
|
template struct New1<X, Y>; // expected-note{{instantiation}}
|
|
|
|
|
|
|
|
template<typename T, typename Arg1, typename Arg2>
|
|
|
|
struct New2 {
|
|
|
|
T* f(bool x, Arg1 a1, Arg2 a2) {
|
|
|
|
return new T(a1, a2); // expected-error{{no matching}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct New2<X, int, float>;
|
|
|
|
template struct New2<X, int, int*>; // expected-note{{instantiation}}
|
|
|
|
// FIXME: template struct New2<int, int, float>;
|
2009-05-22 01:21:12 +08:00
|
|
|
|
2009-12-23 01:13:37 +08:00
|
|
|
// PR5833
|
|
|
|
struct New3 {
|
|
|
|
New3();
|
|
|
|
|
|
|
|
void *operator new[](__SIZE_TYPE__) __attribute__((unavailable)); // expected-note{{explicitly made unavailable}}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class C>
|
|
|
|
void* object_creator() {
|
|
|
|
return new C(); // expected-error{{call to unavailable function 'operator new[]'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
template void *object_creator<New3[4]>(); // expected-note{{instantiation}}
|
|
|
|
|
2009-05-22 01:21:12 +08:00
|
|
|
template<typename T>
|
|
|
|
struct Delete0 {
|
|
|
|
void f(T t) {
|
|
|
|
delete t; // expected-error{{cannot delete}}
|
|
|
|
::delete [] t;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct Delete0<int*>;
|
|
|
|
template struct Delete0<X*>;
|
|
|
|
template struct Delete0<int>; // expected-note{{instantiation}}
|
2009-05-22 01:37:52 +08:00
|
|
|
|
2009-12-13 02:16:41 +08:00
|
|
|
namespace PR5755 {
|
|
|
|
template <class T>
|
|
|
|
void Foo() {
|
|
|
|
char* p = 0;
|
|
|
|
delete[] p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test() {
|
|
|
|
Foo<int>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-22 01:37:52 +08:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// throw expressions
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
template<typename T>
|
|
|
|
struct Throw1 {
|
|
|
|
void f(T t) {
|
|
|
|
throw;
|
|
|
|
throw t; // expected-error{{incomplete type}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-12-24 05:06:06 +08:00
|
|
|
struct Incomplete; // expected-note 2{{forward}}
|
2009-05-22 01:37:52 +08:00
|
|
|
|
|
|
|
template struct Throw1<int>;
|
|
|
|
template struct Throw1<int*>;
|
|
|
|
template struct Throw1<Incomplete*>; // expected-note{{instantiation}}
|
|
|
|
|
2009-05-22 02:34:44 +08:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// typeid expressions
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
class type_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct TypeId0 {
|
|
|
|
const std::type_info &f(T* ptr) {
|
|
|
|
if (ptr)
|
|
|
|
return typeid(ptr);
|
|
|
|
else
|
2009-12-24 05:06:06 +08:00
|
|
|
return typeid(T); // expected-error{{'typeid' of incomplete type 'struct Incomplete'}}
|
2009-05-22 02:34:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Abstract {
|
|
|
|
virtual void f() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct TypeId0<int>;
|
2009-12-24 05:06:06 +08:00
|
|
|
template struct TypeId0<Incomplete>; // expected-note{{instantiation of member function}}
|
2009-05-22 02:34:44 +08:00
|
|
|
template struct TypeId0<Abstract>;
|
2009-05-22 02:55:48 +08:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// type traits
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
template<typename T>
|
|
|
|
struct is_pod {
|
|
|
|
static const bool value = __is_pod(T);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int is_pod0[is_pod<X>::value? -1 : 1];
|
|
|
|
static const int is_pod1[is_pod<Y>::value? 1 : -1];
|
2009-05-22 05:38:12 +08:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// initializer lists
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
template<typename T, typename Val1>
|
|
|
|
struct InitList1 {
|
|
|
|
void f(Val1 val1) {
|
|
|
|
T x = { val1 };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct APair {
|
|
|
|
int *x;
|
|
|
|
const float *y;
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct InitList1<int[1], float>;
|
|
|
|
template struct InitList1<APair, int*>;
|
|
|
|
|
|
|
|
template<typename T, typename Val1, typename Val2>
|
|
|
|
struct InitList2 {
|
|
|
|
void f(Val1 val1, Val2 val2) {
|
|
|
|
T x = { val1, val2 }; // expected-error{{incompatible}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct InitList2<APair, int*, float*>;
|
|
|
|
template struct InitList2<APair, int*, double*>; // expected-note{{instantiation}}
|
2009-05-23 05:13:27 +08:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
// member references
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
template<typename T, typename Result>
|
|
|
|
struct DotMemRef0 {
|
|
|
|
void f(T t) {
|
2009-12-10 07:02:17 +08:00
|
|
|
Result result = t.m; // expected-error{{non-const lvalue reference to type}}
|
2009-05-23 05:13:27 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MemInt {
|
|
|
|
int m;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InheritsMemInt : MemInt { };
|
|
|
|
|
|
|
|
struct MemIntFunc {
|
|
|
|
static int m(int);
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct DotMemRef0<MemInt, int&>;
|
|
|
|
template struct DotMemRef0<InheritsMemInt, int&>;
|
|
|
|
template struct DotMemRef0<MemIntFunc, int (*)(int)>;
|
|
|
|
template struct DotMemRef0<MemInt, float&>; // expected-note{{instantiation}}
|
|
|
|
|
|
|
|
template<typename T, typename Result>
|
|
|
|
struct ArrowMemRef0 {
|
|
|
|
void f(T t) {
|
2009-12-10 07:02:17 +08:00
|
|
|
Result result = t->m; // expected-error 2{{non-const lvalue reference}}
|
2009-05-23 05:13:27 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct ArrowWrapper {
|
|
|
|
T operator->();
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct ArrowMemRef0<MemInt*, int&>;
|
|
|
|
template struct ArrowMemRef0<InheritsMemInt*, int&>;
|
|
|
|
template struct ArrowMemRef0<MemIntFunc*, int (*)(int)>;
|
|
|
|
template struct ArrowMemRef0<MemInt*, float&>; // expected-note{{instantiation}}
|
|
|
|
|
|
|
|
template struct ArrowMemRef0<ArrowWrapper<MemInt*>, int&>;
|
|
|
|
template struct ArrowMemRef0<ArrowWrapper<InheritsMemInt*>, int&>;
|
|
|
|
template struct ArrowMemRef0<ArrowWrapper<MemIntFunc*>, int (*)(int)>;
|
|
|
|
template struct ArrowMemRef0<ArrowWrapper<MemInt*>, float&>; // expected-note{{instantiation}}
|
|
|
|
template struct ArrowMemRef0<ArrowWrapper<ArrowWrapper<MemInt*> >, int&>;
|
|
|
|
|
|
|
|
// FIXME: we should be able to return a MemInt without the reference!
|
|
|
|
MemInt &createMemInt(int);
|
|
|
|
|
|
|
|
template<int N>
|
|
|
|
struct NonDepMemberExpr0 {
|
|
|
|
void f() {
|
|
|
|
createMemInt(N).m = N;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct NonDepMemberExpr0<0>;
|
2009-05-23 05:26:58 +08:00
|
|
|
|
|
|
|
template<typename T, typename Result>
|
|
|
|
struct MemberFuncCall0 {
|
|
|
|
void f(T t) {
|
|
|
|
Result result = t.f();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct HasMemFunc0 {
|
|
|
|
T f();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template struct MemberFuncCall0<HasMemFunc0<int&>, const int&>;
|
|
|
|
|
|
|
|
template<typename Result>
|
|
|
|
struct ThisMemberFuncCall0 {
|
|
|
|
Result g();
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
Result r1 = g();
|
|
|
|
Result r2 = this->g();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct ThisMemberFuncCall0<int&>;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct NonDepMemberCall0 {
|
|
|
|
void foo(HasMemFunc0<int&> x) {
|
2009-12-10 07:02:17 +08:00
|
|
|
T result = x.f(); // expected-error{{non-const lvalue reference}}
|
2009-05-23 05:26:58 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct NonDepMemberCall0<int&>;
|
|
|
|
template struct NonDepMemberCall0<const int&>;
|
|
|
|
template struct NonDepMemberCall0<float&>; // expected-note{{instantiation}}
|
2009-05-23 07:47:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct QualifiedDeclRef0 {
|
|
|
|
T f() {
|
Switch the initialization required by return statements over to the
new InitializationSequence. This fixes some bugs (e.g., PR5808),
changed some diagnostics, and caused more churn than expected. What's
new:
- InitializationSequence now has a "C conversion sequence" category
and step kind, which falls back to
- Changed the diagnostics for returns to always have the result type
of the function first and the type of the expression second.
CheckSingleAssignmentConstraints to peform checking in C.
- Improved ASTs for initialization of return values. The ASTs now
capture all of the temporaries we need to create, but
intentionally do not bind the tempoary that is actually returned,
so that it won't get destroyed twice.
- Make sure to perform an (elidable!) copy of the class object that
is returned from a class.
- Fix copy elision in CodeGen to properly see through the
subexpressions that occur with elidable copies.
- Give "new" its own entity kind; as with return values and thrown
objects, we don't bind the expression so we don't call a
destructor for it.
Note that, with this patch, I've broken returning move-only types in
C++0x. We'll fix it later, when we tackle NRVO.
llvm-svn: 91669
2009-12-18 13:02:21 +08:00
|
|
|
return is_pod<X>::value; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'bool const'}}
|
2009-05-23 07:47:06 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template struct QualifiedDeclRef0<bool>;
|
|
|
|
template struct QualifiedDeclRef0<int&>; // expected-note{{instantiation}}
|