blob: 7f1ff3dc316c4aed81782888089f85336c99a61d [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 Gregord5a423b2009-09-25 18:43:00 +00005template x; // expected-error {{C++ requires a type specifier for all declarations}} \
6 // expected-error {{does not refer}}
Douglas Gregor7cdbc582009-07-22 23:48:44 +00007export template x; // expected-error {{expected '<' after 'template'}}
8export template<class T> class x0; // expected-note {{exported templates are unsupported}}
Sebastian Redla4ed0d82008-12-28 15:28:59 +00009template < ; // expected-error {{parse error}} expected-error {{declaration does not declare anything}}
10template <template X> struct Err1; // expected-error {{expected '<' after 'template'}}
11template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}}
12template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}}
Douglas Gregoradcac882008-12-01 23:54:00 +000013
14// Template function declarations
15template <typename T> void foo();
16template <typename T, typename U> void foo();
17
Douglas Gregor26236e82008-12-02 00:41:28 +000018// Template function definitions.
19template <typename T> void foo() { }
Douglas Gregoradcac882008-12-01 23:54:00 +000020
21// Template class (forward) declarations
22template <typename T> struct A;
23template <typename T, typename U> struct b;
24template <typename> struct C;
25template <typename, typename> struct D;
26
27// Forward declarations with default parameters?
Douglas Gregor4310f4e2009-02-16 22:38:20 +000028template <typename T = int> class X1;
29template <typename = int> class X2;
Douglas Gregoradcac882008-12-01 23:54:00 +000030
31// Forward declarations w/template template parameters
32template <template <typename> class T> class TTP1;
33template <template <typename> class> class TTP2;
Douglas Gregore53060f2009-06-25 22:08:12 +000034template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}}
35template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}}
Douglas Gregoraaba5e32009-02-04 19:02:06 +000036template <template <typename X, typename Y> class T> class TTP5;
Douglas Gregoradcac882008-12-01 23:54:00 +000037
Douglas Gregor52591bf2009-06-24 00:54:41 +000038// Forward declarations with non-type params
Douglas Gregoradcac882008-12-01 23:54:00 +000039template <int> class NTP0;
40template <int N> class NTP1;
41template <int N = 5> class NTP2;
42template <int = 10> class NTP3;
Douglas Gregor4310f4e2009-02-16 22:38:20 +000043template <unsigned int N = 12u> class NTP4;
44template <unsigned int = 12u> class NTP5;
45template <unsigned = 15u> class NTP6;
46template <typename T, T Obj> class NTP7;
Douglas Gregoradcac882008-12-01 23:54:00 +000047
48// Template class declarations
49template <typename T> struct A { };
50template <typename T, typename U> struct B { };
51
Douglas Gregor72c3f312008-12-05 18:15:24 +000052// Template parameter shadowing
53template<typename T, // expected-note{{template parameter is declared here}}
Mike Stump1eb44332009-09-09 15:08:12 +000054 typename T> // expected-error{{declaration of 'T' shadows template parameter}}
Douglas Gregor72c3f312008-12-05 18:15:24 +000055 void shadow1();
56
57template<typename T> // expected-note{{template parameter is declared here}}
58void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}}
59
60template<typename T> // expected-note{{template parameter is declared here}}
61class T { // expected-error{{declaration of 'T' shadows template parameter}}
62};
63
64template<int Size> // expected-note{{template parameter is declared here}}
65void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}}
66
Douglas Gregorc19ee3e2009-06-17 23:37:01 +000067// <rdar://problem/6952203>
68template<typename T> // expected-note{{here}}
69struct shadow4 {
70 int T; // expected-error{{shadows}}
71};
72
73template<typename T> // expected-note{{here}}
74struct shadow5 {
75 int T(int, float); // expected-error{{shadows}}
76};
77
Douglas Gregor72c3f312008-12-05 18:15:24 +000078// Non-type template parameters in scope
79template<int Size>
80void f(int& i) {
81 i = Size;
82 Size = i; // expected-error{{expression is not assignable}}
83}
84
85template<typename T>
86const T& min(const T&, const T&);
Argyrios Kyrtzidis64096252009-05-22 10:22:18 +000087
88void f2() {
89 int x;
90 A< typeof(x>1) > a;
91}