blob: ec333de8b4f17a9b9360b20657ff31f6095c62f1 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregoradcac882008-12-01 23:54:00 +00002
3// Errors
4export class foo { }; // expected-error {{expected template}}
Douglas Gregor4310f4e2009-02-16 22:38:20 +00005template x; // expected-error {{expected '<' after 'template'}} \
6// expected-error {{C++ requires a type specifier for all declarations}}
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00007export template x; // expected-error {{expected '<' after 'template'}} \
Douglas Gregor4310f4e2009-02-16 22:38:20 +00008 // expected-note {{exported templates are unsupported}} \
9// expected-error {{C++ requires a type specifier for all declarations}}
Sebastian Redla4ed0d82008-12-28 15:28:59 +000010// See Sema::ParsedFreeStandingDeclSpec about the double diagnostic. This is
11// because ParseNonTypeTemplateParameter starts parsing a DeclSpec.
12template < ; // expected-error {{parse error}} expected-error {{declaration does not declare anything}}
13template <template X> struct Err1; // expected-error {{expected '<' after 'template'}}
14template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}}
15template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}}
Douglas Gregoradcac882008-12-01 23:54:00 +000016
17// Template function declarations
18template <typename T> void foo();
19template <typename T, typename U> void foo();
20
Douglas Gregor26236e82008-12-02 00:41:28 +000021// Template function definitions.
22template <typename T> void foo() { }
Douglas Gregoradcac882008-12-01 23:54:00 +000023
24// Template class (forward) declarations
25template <typename T> struct A;
26template <typename T, typename U> struct b;
27template <typename> struct C;
28template <typename, typename> struct D;
29
30// Forward declarations with default parameters?
Douglas Gregor4310f4e2009-02-16 22:38:20 +000031template <typename T = int> class X1;
32template <typename = int> class X2;
Douglas Gregoradcac882008-12-01 23:54:00 +000033
34// Forward declarations w/template template parameters
35template <template <typename> class T> class TTP1;
36template <template <typename> class> class TTP2;
Douglas Gregord684b002009-02-10 19:49:53 +000037template <template <typename> class T = foo> class TTP3; // FIXME:expected-error{{template argument for template template parameter must be a template}}
38template <template <typename> class = foo> class TTP3; // FIXME:expected-error{{template argument for template template parameter must be a template}}
Douglas Gregoraaba5e32009-02-04 19:02:06 +000039template <template <typename X, typename Y> class T> class TTP5;
Douglas Gregoradcac882008-12-01 23:54:00 +000040
41// Forward declararations with non-type params
42template <int> class NTP0;
43template <int N> class NTP1;
44template <int N = 5> class NTP2;
45template <int = 10> class NTP3;
Douglas Gregor4310f4e2009-02-16 22:38:20 +000046template <unsigned int N = 12u> class NTP4;
47template <unsigned int = 12u> class NTP5;
48template <unsigned = 15u> class NTP6;
49template <typename T, T Obj> class NTP7;
Douglas Gregoradcac882008-12-01 23:54:00 +000050
51// Template class declarations
52template <typename T> struct A { };
53template <typename T, typename U> struct B { };
54
Douglas Gregor72c3f312008-12-05 18:15:24 +000055// Template parameter shadowing
56template<typename T, // expected-note{{template parameter is declared here}}
57 typename T> // expected-error{{declaration of 'T' shadows template parameter}}
58 void shadow1();
59
60template<typename T> // expected-note{{template parameter is declared here}}
61void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}}
62
63template<typename T> // expected-note{{template parameter is declared here}}
64class T { // expected-error{{declaration of 'T' shadows template parameter}}
65};
66
67template<int Size> // expected-note{{template parameter is declared here}}
68void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}}
69
70// Non-type template parameters in scope
71template<int Size>
72void f(int& i) {
73 i = Size;
74 Size = i; // expected-error{{expression is not assignable}}
75}
76
77template<typename T>
78const T& min(const T&, const T&);