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