2008-12-02 07:54:00 +08:00
|
|
|
// RUN: clang -fsyntax-only -verify %s
|
|
|
|
|
|
|
|
// Errors
|
|
|
|
export class foo { }; // expected-error {{expected template}}
|
|
|
|
template x; // expected-error {{expected '<' after 'template'}}
|
2008-12-24 10:52:09 +08:00
|
|
|
export template x; // expected-error {{expected '<' after 'template'}} \
|
|
|
|
// expected-note {{exported templates are unsupported}}
|
2008-12-02 07:54:00 +08:00
|
|
|
template < ; // expected-error {{parse error}}
|
|
|
|
template <template X> ; // expected-error {{expected '<' after 'template'}}
|
|
|
|
template <template <typename> > ; // expected-error {{expected 'class' before '>'}}
|
|
|
|
template <template <typename> Foo> ; // expected-error {{expected 'class' before 'Foo'}}
|
|
|
|
|
|
|
|
// 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?
|
|
|
|
template <typename T = int> X1;
|
|
|
|
template <typename = int> X2;
|
|
|
|
|
|
|
|
// Forward declarations w/template template parameters
|
|
|
|
template <template <typename> class T> class TTP1;
|
|
|
|
template <template <typename> class> class TTP2;
|
|
|
|
template <template <typename> class T = foo> TTP3;
|
|
|
|
template <template <typename> class = foo> TTP3;
|
|
|
|
template <template <typename X, typename Y> class T> TTP5;
|
|
|
|
|
|
|
|
// Forward declararations with non-type params
|
|
|
|
template <int> class NTP0;
|
|
|
|
template <int N> class NTP1;
|
|
|
|
template <int N = 5> class NTP2;
|
|
|
|
template <int = 10> class NTP3;
|
|
|
|
template <unsigned int N = 12u> NTP4;;
|
|
|
|
template <unsigned int = 12u> NTP5;
|
|
|
|
template <unsigned = 15u> NTP6;
|
2008-12-06 02:15:24 +08:00
|
|
|
template <typename T, T Obj> 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}}
|
|
|
|
typename T> // expected-error{{declaration of 'T' shadows template parameter}}
|
|
|
|
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}}
|
|
|
|
|
|
|
|
// 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&);
|