blob: 69550187909852f05ac3ae046880ca2d88f695f7 [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 Gregor1426e532009-05-12 21:31:51 +00005template x; // expected-error {{C++ requires a type specifier for all declarations}}
Douglas Gregorc4b4e7b2008-12-24 02:52:09 +00006export template x; // expected-error {{expected '<' after 'template'}} \
Douglas Gregor4310f4e2009-02-16 22:38:20 +00007 // expected-note {{exported templates are unsupported}} \
8// expected-error {{C++ requires a type specifier for all declarations}}
Sebastian Redla4ed0d82008-12-28 15:28:59 +00009// See Sema::ParsedFreeStandingDeclSpec about the double diagnostic. This is
10// because ParseNonTypeTemplateParameter starts parsing a DeclSpec.
11template < ; // expected-error {{parse error}} expected-error {{declaration does not declare anything}}
12template <template X> struct Err1; // expected-error {{expected '<' after 'template'}}
13template <template <typename> > struct Err2; // expected-error {{expected 'class' before '>'}}
14template <template <typename> Foo> struct Err3; // expected-error {{expected 'class' before 'Foo'}}
Douglas Gregoradcac882008-12-01 23:54:00 +000015
16// Template function declarations
17template <typename T> void foo();
18template <typename T, typename U> void foo();
19
Douglas Gregor26236e82008-12-02 00:41:28 +000020// Template function definitions.
21template <typename T> void foo() { }
Douglas Gregoradcac882008-12-01 23:54:00 +000022
23// Template class (forward) declarations
24template <typename T> struct A;
25template <typename T, typename U> struct b;
26template <typename> struct C;
27template <typename, typename> struct D;
28
29// Forward declarations with default parameters?
Douglas Gregor4310f4e2009-02-16 22:38:20 +000030template <typename T = int> class X1;
31template <typename = int> class X2;
Douglas Gregoradcac882008-12-01 23:54:00 +000032
33// Forward declarations w/template template parameters
34template <template <typename> class T> class TTP1;
35template <template <typename> class> class TTP2;
Douglas Gregore53060f2009-06-25 22:08:12 +000036template <template <typename> class T = foo> class TTP3; // expected-error{{must be a class template}}
37template <template <typename> class = foo> class TTP3; // expected-error{{must be a class template}}
Douglas Gregoraaba5e32009-02-04 19:02:06 +000038template <template <typename X, typename Y> class T> class TTP5;
Douglas Gregoradcac882008-12-01 23:54:00 +000039
Douglas Gregor52591bf2009-06-24 00:54:41 +000040// Forward declarations with non-type params
Douglas Gregoradcac882008-12-01 23:54:00 +000041template <int> class NTP0;
42template <int N> class NTP1;
43template <int N = 5> class NTP2;
44template <int = 10> class NTP3;
Douglas Gregor4310f4e2009-02-16 22:38:20 +000045template <unsigned int N = 12u> class NTP4;
46template <unsigned int = 12u> class NTP5;
47template <unsigned = 15u> class NTP6;
48template <typename T, T Obj> class NTP7;
Douglas Gregoradcac882008-12-01 23:54:00 +000049
50// Template class declarations
51template <typename T> struct A { };
52template <typename T, typename U> struct B { };
53
Douglas Gregor72c3f312008-12-05 18:15:24 +000054// Template parameter shadowing
55template<typename T, // expected-note{{template parameter is declared here}}
56 typename T> // expected-error{{declaration of 'T' shadows template parameter}}
57 void shadow1();
58
59template<typename T> // expected-note{{template parameter is declared here}}
60void shadow2(int T); // expected-error{{declaration of 'T' shadows template parameter}}
61
62template<typename T> // expected-note{{template parameter is declared here}}
63class T { // expected-error{{declaration of 'T' shadows template parameter}}
64};
65
66template<int Size> // expected-note{{template parameter is declared here}}
67void shadow3(int Size); // expected-error{{declaration of 'Size' shadows template parameter}}
68
Douglas Gregorc19ee3e2009-06-17 23:37:01 +000069// <rdar://problem/6952203>
70template<typename T> // expected-note{{here}}
71struct shadow4 {
72 int T; // expected-error{{shadows}}
73};
74
75template<typename T> // expected-note{{here}}
76struct shadow5 {
77 int T(int, float); // expected-error{{shadows}}
78};
79
Douglas Gregor72c3f312008-12-05 18:15:24 +000080// Non-type template parameters in scope
81template<int Size>
82void f(int& i) {
83 i = Size;
84 Size = i; // expected-error{{expression is not assignable}}
85}
86
87template<typename T>
88const T& min(const T&, const T&);
Argyrios Kyrtzidis64096252009-05-22 10:22:18 +000089
90void f2() {
91 int x;
92 A< typeof(x>1) > a;
93}