2009-03-24 10:24:46 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only -verify %s
|
2008-12-02 07:54:00 +08:00
|
|
|
|
|
|
|
// Errors
|
|
|
|
export class foo { }; // expected-error {{expected template}}
|
2009-09-26 02:43:00 +08:00
|
|
|
template x; // expected-error {{C++ requires a type specifier for all declarations}} \
|
|
|
|
// expected-error {{does not refer}}
|
2009-07-23 07:48:44 +08:00
|
|
|
export template x; // expected-error {{expected '<' after 'template'}}
|
|
|
|
export template<class T> class x0; // expected-note {{exported templates are unsupported}}
|
2008-12-28 23:28:59 +08:00
|
|
|
template < ; // expected-error {{parse error}} expected-error {{declaration does not declare anything}}
|
|
|
|
template <template X> struct Err1; // expected-error {{expected '<' after 'template'}}
|
|
|
|
template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}}
|
|
|
|
template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}}
|
2008-12-02 07:54:00 +08:00
|
|
|
|
|
|
|
// Template function declarations
|
|
|
|
template <typename T> void foo();
|
|
|
|
template <typename T, typename U> void foo();
|
|
|
|
|
2008-12-02 08:41:28 +08:00
|
|
|
// Template function definitions.
|
|
|
|
template <typename T> void foo() { }
|
2008-12-02 07:54:00 +08:00
|
|
|
|
|
|
|
// Template class (forward) declarations
|
|
|
|
template <typename T> struct A;
|
|
|
|
template <typename T, typename U> struct b;
|
|
|
|
template <typename> struct C;
|
|
|
|
template <typename, typename> struct D;
|
|
|
|
|
|
|
|
// Forward declarations with default parameters?
|
2009-02-17 06:38:20 +08:00
|
|
|
template <typename T = int> class X1;
|
|
|
|
template <typename = int> class X2;
|
2008-12-02 07:54:00 +08:00
|
|
|
|
|
|
|
// Forward declarations w/template template parameters
|
|
|
|
template <template <typename> class T> class TTP1;
|
|
|
|
template <template <typename> class> class TTP2;
|
2009-06-26 06:08:12 +08:00
|
|
|
template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}}
|
|
|
|
template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}}
|
2009-02-05 03:02:06 +08:00
|
|
|
template <template <typename X, typename Y> class T> class TTP5;
|
2008-12-02 07:54:00 +08:00
|
|
|
|
2009-06-24 08:54:41 +08:00
|
|
|
// Forward declarations with non-type params
|
2008-12-02 07:54:00 +08:00
|
|
|
template <int> class NTP0;
|
|
|
|
template <int N> class NTP1;
|
|
|
|
template <int N = 5> class NTP2;
|
|
|
|
template <int = 10> class NTP3;
|
2009-02-17 06:38:20 +08:00
|
|
|
template <unsigned int N = 12u> class NTP4;
|
|
|
|
template <unsigned int = 12u> class NTP5;
|
|
|
|
template <unsigned = 15u> class NTP6;
|
|
|
|
template <typename T, T Obj> class NTP7;
|
2008-12-02 07:54:00 +08:00
|
|
|
|
|
|
|
// Template class declarations
|
|
|
|
template <typename T> struct A { };
|
|
|
|
template <typename T, typename U> struct B { };
|
|
|
|
|
2008-12-06 02:15:24 +08:00
|
|
|
// Template parameter shadowing
|
|
|
|
template<typename T, // expected-note{{template parameter is declared here}}
|
2009-09-09 23:08:12 +08:00
|
|
|
typename T> // expected-error{{declaration of 'T' shadows template parameter}}
|
2008-12-06 02:15:24 +08:00
|
|
|
void shadow1();
|
|
|
|
|
|
|
|
template<typename T> // expected-note{{template parameter is declared here}}
|
|
|
|
void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}}
|
|
|
|
|
|
|
|
template<typename T> // expected-note{{template parameter is declared here}}
|
|
|
|
class T { // expected-error{{declaration of 'T' shadows template parameter}}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<int Size> // expected-note{{template parameter is declared here}}
|
|
|
|
void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}}
|
|
|
|
|
2009-06-18 07:37:01 +08:00
|
|
|
// <rdar://problem/6952203>
|
|
|
|
template<typename T> // expected-note{{here}}
|
|
|
|
struct shadow4 {
|
|
|
|
int T; // expected-error{{shadows}}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T> // expected-note{{here}}
|
|
|
|
struct shadow5 {
|
|
|
|
int T(int, float); // expected-error{{shadows}}
|
|
|
|
};
|
|
|
|
|
2008-12-06 02:15:24 +08:00
|
|
|
// Non-type template parameters in scope
|
|
|
|
template<int Size>
|
|
|
|
void f(int& i) {
|
|
|
|
i = Size;
|
|
|
|
Size = i; // expected-error{{expression is not assignable}}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
const T& min(const T&, const T&);
|
2009-05-22 18:22:18 +08:00
|
|
|
|
|
|
|
void f2() {
|
|
|
|
int x;
|
|
|
|
A< typeof(x>1) > a;
|
|
|
|
}
|