Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | |
| 3 | // Errors |
| 4 | export class foo { }; // expected-error {{expected template}} |
| 5 | template x; // expected-error {{expected '<' after 'template'}} |
Douglas Gregor | c4b4e7b | 2008-12-24 02:52:09 +0000 | [diff] [blame] | 6 | export template x; // expected-error {{expected '<' after 'template'}} \ |
| 7 | // expected-note {{exported templates are unsupported}} |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 8 | // See Sema::ParsedFreeStandingDeclSpec about the double diagnostic. This is |
| 9 | // because ParseNonTypeTemplateParameter starts parsing a DeclSpec. |
| 10 | template < ; // expected-error {{parse error}} expected-error {{declaration does not declare anything}} |
| 11 | template <template X> struct Err1; // expected-error {{expected '<' after 'template'}} |
| 12 | template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}} |
| 13 | template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}} |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 14 | |
| 15 | // Template function declarations |
| 16 | template <typename T> void foo(); |
| 17 | template <typename T, typename U> void foo(); |
| 18 | |
Douglas Gregor | 26236e8 | 2008-12-02 00:41:28 +0000 | [diff] [blame] | 19 | // Template function definitions. |
| 20 | template <typename T> void foo() { } |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 21 | |
| 22 | // Template class (forward) declarations |
| 23 | template <typename T> struct A; |
| 24 | template <typename T, typename U> struct b; |
| 25 | template <typename> struct C; |
| 26 | template <typename, typename> struct D; |
| 27 | |
| 28 | // Forward declarations with default parameters? |
| 29 | template <typename T = int> X1; |
| 30 | template <typename = int> X2; |
| 31 | |
| 32 | // Forward declarations w/template template parameters |
| 33 | template <template <typename> class T> class TTP1; |
| 34 | template <template <typename> class> class TTP2; |
Douglas Gregor | aaba5e3 | 2009-02-04 19:02:06 +0000 | [diff] [blame^] | 35 | template <template <typename> class T = foo> class TTP3; |
| 36 | template <template <typename> class = foo> class TTP3; |
| 37 | template <template <typename X, typename Y> class T> class TTP5; |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 38 | |
| 39 | // Forward declararations with non-type params |
| 40 | template <int> class NTP0; |
| 41 | template <int N> class NTP1; |
| 42 | template <int N = 5> class NTP2; |
| 43 | template <int = 10> class NTP3; |
| 44 | template <unsigned int N = 12u> NTP4;; |
| 45 | template <unsigned int = 12u> NTP5; |
| 46 | template <unsigned = 15u> NTP6; |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 47 | template <typename T, T Obj> NTP7; |
Douglas Gregor | adcac88 | 2008-12-01 23:54:00 +0000 | [diff] [blame] | 48 | |
| 49 | // Template class declarations |
| 50 | template <typename T> struct A { }; |
| 51 | template <typename T, typename U> struct B { }; |
| 52 | |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 53 | // Template parameter shadowing |
| 54 | template<typename T, // expected-note{{template parameter is declared here}} |
| 55 | typename T> // expected-error{{declaration of 'T' shadows template parameter}} |
| 56 | void shadow1(); |
| 57 | |
| 58 | template<typename T> // expected-note{{template parameter is declared here}} |
| 59 | void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}} |
| 60 | |
| 61 | template<typename T> // expected-note{{template parameter is declared here}} |
| 62 | class T { // expected-error{{declaration of 'T' shadows template parameter}} |
| 63 | }; |
| 64 | |
| 65 | template<int Size> // expected-note{{template parameter is declared here}} |
| 66 | void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}} |
| 67 | |
| 68 | // Non-type template parameters in scope |
| 69 | template<int Size> |
| 70 | void f(int& i) { |
| 71 | i = Size; |
| 72 | Size = i; // expected-error{{expression is not assignable}} |
| 73 | } |
| 74 | |
| 75 | template<typename T> |
| 76 | const T& min(const T&, const T&); |