2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2009-08-28 00:57:43 +08:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct X0 {
|
|
|
|
template<typename U> T f0(U);
|
|
|
|
template<typename U> U& f1(T*, U); // expected-error{{pointer to a reference}} \
|
|
|
|
// expected-note{{candidate}}
|
|
|
|
};
|
|
|
|
|
|
|
|
X0<int> x0i;
|
|
|
|
X0<void> x0v;
|
|
|
|
X0<int&> x0ir; // expected-note{{instantiation}}
|
|
|
|
|
|
|
|
void test_X0(int *ip, double *dp) {
|
|
|
|
X0<int> xi;
|
|
|
|
int i1 = xi.f0(ip);
|
|
|
|
double *&dpr = xi.f1(ip, dp);
|
|
|
|
xi.f1(dp, dp); // expected-error{{no matching}}
|
|
|
|
|
|
|
|
X0<void> xv;
|
|
|
|
double *&dpr2 = xv.f1(ip, dp);
|
|
|
|
}
|
2009-08-29 01:37:35 +08:00
|
|
|
|
2009-08-29 04:31:08 +08:00
|
|
|
template<typename T>
|
|
|
|
struct X1 {
|
|
|
|
template<typename U>
|
|
|
|
struct Inner0 {
|
|
|
|
U x;
|
|
|
|
T y; // expected-error{{void}}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
struct Inner1 {
|
|
|
|
U x; // expected-error{{void}}
|
2009-08-29 04:50:45 +08:00
|
|
|
T y;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
struct Inner2 {
|
|
|
|
struct SuperInner {
|
|
|
|
U z; // expected-error{{void}}
|
|
|
|
};
|
2009-08-29 04:31:08 +08:00
|
|
|
};
|
2009-08-29 05:09:48 +08:00
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
struct Inner3 {
|
|
|
|
void f0(T t, U u) {
|
|
|
|
(void)(t + u); // expected-error{{invalid operands}}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename V>
|
|
|
|
V f1(T t, U u, V) {
|
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 t + u; // expected-error{{cannot initialize return object}}
|
2009-08-29 05:09:48 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-29 05:15:08 +08:00
|
|
|
template<typename U>
|
|
|
|
struct Inner4;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
template<typename U>
|
|
|
|
struct X1<T>::Inner4 {
|
|
|
|
template<typename V>
|
|
|
|
V f2(T t, U u, V);
|
2009-08-29 05:41:19 +08:00
|
|
|
|
|
|
|
static U value;
|
2009-08-29 04:31:08 +08:00
|
|
|
};
|
|
|
|
|
2009-08-29 05:41:19 +08:00
|
|
|
template<typename T>
|
|
|
|
template<typename U>
|
|
|
|
U X1<T>::Inner4<U>::value; // expected-error{{reference variable}}
|
|
|
|
|
2009-08-29 05:15:08 +08:00
|
|
|
template<typename T>
|
|
|
|
template<typename U>
|
|
|
|
template<typename V>
|
|
|
|
V X1<T>::Inner4<U>::f2(T t, U u, V) {
|
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 t + u; // expected-error{{cannot initialize return object}}
|
2009-08-29 05:15:08 +08:00
|
|
|
}
|
|
|
|
|
2009-08-29 05:09:48 +08:00
|
|
|
void test_X1(int *ip, int i, double *dp) {
|
2009-08-29 04:31:08 +08:00
|
|
|
X1<void>::Inner0<int> *xvip; // okay
|
|
|
|
X1<void>::Inner0<int> xvi; // expected-note{{instantiation}}
|
|
|
|
|
|
|
|
X1<int>::Inner1<void> *xivp; // okay
|
|
|
|
X1<int>::Inner1<void> xiv; // expected-note{{instantiation}}
|
2009-08-29 04:50:45 +08:00
|
|
|
|
|
|
|
X1<int>::Inner2<void>::SuperInner *xisivp; // okay
|
|
|
|
X1<int>::Inner2<void>::SuperInner xisiv; // expected-note{{instantiation}}
|
2009-08-29 05:09:48 +08:00
|
|
|
|
|
|
|
X1<int*>::Inner3<int> id3;
|
|
|
|
id3.f0(ip, i);
|
2009-12-22 15:24:36 +08:00
|
|
|
id3.f0(dp, i); // expected-error{{cannot initialize a parameter of type 'int *' with an lvalue of type 'double *'}}
|
2009-08-29 05:09:48 +08:00
|
|
|
id3.f1(ip, i, ip);
|
|
|
|
id3.f1(ip, i, dp); // expected-note{{instantiation}}
|
|
|
|
|
|
|
|
X1<int*>::Inner3<double*> id3b;
|
|
|
|
id3b.f0(ip, dp); // expected-note{{instantiation}}
|
2009-08-29 05:15:08 +08:00
|
|
|
|
|
|
|
X1<int*>::Inner4<int> id4;
|
|
|
|
id4.f2(ip, i, dp); // expected-note{{instantiation}}
|
2009-08-29 05:41:19 +08:00
|
|
|
|
|
|
|
X1<int*>::Inner4<int>::value = 17;
|
|
|
|
i = X1<int*>::Inner4<int&>::value; // expected-note{{instantiation}}
|
2009-08-29 04:31:08 +08:00
|
|
|
}
|
2009-11-10 02:29:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct X2 {
|
|
|
|
template<T *Ptr> // expected-error{{pointer to a reference}}
|
|
|
|
struct Inner;
|
|
|
|
|
|
|
|
template<T Value> // expected-error{{cannot have type 'float'}}
|
|
|
|
struct Inner2;
|
|
|
|
};
|
|
|
|
|
|
|
|
X2<int&> x2a; // expected-note{{instantiation}}
|
|
|
|
X2<float> x2b; // expected-note{{instantiation}}
|
2009-11-21 03:42:02 +08:00
|
|
|
|
|
|
|
namespace N0 {
|
|
|
|
template<typename T>
|
|
|
|
struct X0 { };
|
|
|
|
|
|
|
|
struct X1 {
|
|
|
|
template<typename T> void f(X0<T>& vals) { g(vals); }
|
|
|
|
template<typename T> void g(X0<T>& vals) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
void test(X1 x1, X0<int> x0i, X0<long> x0l) {
|
|
|
|
x1.f(x0i);
|
|
|
|
x1.f(x0l);
|
|
|
|
}
|
|
|
|
}
|
2010-02-06 06:40:03 +08:00
|
|
|
|
|
|
|
namespace PR6239 {
|
|
|
|
template <typename T>
|
|
|
|
struct X0 {
|
|
|
|
class type {
|
|
|
|
typedef T E;
|
|
|
|
template <E e> // subsitute T for E and bug goes away
|
|
|
|
struct sfinae { };
|
|
|
|
|
|
|
|
template <class U>
|
|
|
|
typename sfinae<&U::operator=>::type test(int);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct X1 {
|
|
|
|
typedef T E;
|
|
|
|
template <E e> // subsitute T for E and bug goes away
|
|
|
|
struct sfinae { };
|
|
|
|
|
|
|
|
template <class U>
|
|
|
|
typename sfinae<&U::operator=>::type test(int);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|