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