1 // RUN: %clang_cc1 -fsyntax-only -verify %s 2 3 // Errors 4 export class foo { }; // expected-error {{expected template}} 5 template x; // expected-error {{C++ requires a type specifier for all declarations}} \ 6 // expected-error {{does not refer}} 7 export template x; // expected-error {{expected '<' after 'template'}} 8 export template<class T> class x0; // expected-warning {{exported templates are unsupported}} 9 template < ; // expected-error {{parse error}} \ 10 // expected-error{{expected ',' or '>' in template-parameter-list}} \ 11 // expected-warning {{declaration does not declare anything}} 12 template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} \ 13 // expected-error{{extraneous}} 14 template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}} \ 15 // expected-error{{extraneous}} 16 template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}} \ 17 // expected-error{{extraneous}} 18 19 // Template function declarations 20 template <typename T> void foo(); 21 template <typename T, typename U> void foo(); 22 23 // Template function definitions. 24 template <typename T> void foo() { } 25 26 // Template class (forward) declarations 27 template <typename T> struct A; 28 template <typename T, typename U> struct b; 29 template <typename> struct C; 30 template <typename, typename> struct D; 31 32 // Forward declarations with default parameters? 33 template <typename T = int> class X1; 34 template <typename = int> class X2; 35 36 // Forward declarations w/template template parameters 37 template <template <typename> class T> class TTP1; 38 template <template <typename> class> class TTP2; 39 template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}} 40 template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}} 41 template <template <typename X, typename Y> class T> class TTP5; 42 43 // Forward declarations with non-type params 44 template <int> class NTP0; 45 template <int N> class NTP1; 46 template <int N = 5> class NTP2; 47 template <int = 10> class NTP3; 48 template <unsigned int N = 12u> class NTP4; 49 template <unsigned int = 12u> class NTP5; 50 template <unsigned = 15u> class NTP6; 51 template <typename T, T Obj> class NTP7; 52 53 // Template class declarations 54 template <typename T> struct A { }; 55 template <typename T, typename U> struct B { }; 56 57 // Template parameter shadowing 58 template<typename T, // expected-note{{template parameter is declared here}} 59 typename T> // expected-error{{declaration of 'T' shadows template parameter}} 60 void shadow1(); 61 62 template<typename T> // expected-note{{template parameter is declared here}} 63 void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}} 64 65 template<typename T> // expected-note{{template parameter is declared here}} 66 class T { // expected-error{{declaration of 'T' shadows template parameter}} 67 }; 68 69 template<int Size> // expected-note{{template parameter is declared here}} 70 void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}} 71 72 // <rdar://problem/6952203> 73 template<typename T> // expected-note{{here}} 74 struct shadow4 { 75 int T; // expected-error{{shadows}} 76 }; 77 78 template<typename T> // expected-note{{here}} 79 struct shadow5 { 80 int T(int, float); // expected-error{{shadows}} 81 }; 82 83 // Non-type template parameters in scope 84 template<int Size> 85 void f(int& i) { 86 i = Size; 87 Size = i; // expected-error{{expression is not assignable}} 88 } 89 90 template<typename T> 91 const T& min(const T&, const T&); 92 93 void f2() { 94 int x; 95 A< typeof(x>1) > a; 96 } 97 98 99 // PR3844 100 template <> struct S<int> { }; // expected-error{{explicit specialization of non-template struct 'S'}} 101 102 namespace PR6184 { 103 namespace N { 104 template <typename T> 105 void bar(typename T::x); 106 } 107 108 template <typename T> 109 void N::bar(typename T::x) { } 110 } 111