blob: b721aab35464599d2dd197e5b068831953effc3d [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregorcd72ba92009-02-06 22:42:48 +00002
3template<typename T> class A;
4
5extern "C++" {
6 template<typename T> class B;
7}
8
9namespace N {
10 template<typename T> class C;
11}
12
13extern "C" {
14 template<typename T> class D; // expected-error{{templates must have C++ linkage}}
15}
16
Benjamin Kramer35e6fee2014-02-02 16:35:43 +000017extern "C" {
18 class PR17968 {
19 template<typename T> class D; // expected-error{{templates must have C++ linkage}}
20 template<typename T> void f(); // expected-error{{templates must have C++ linkage}}
21 };
22}
23
Douglas Gregorf9aa5262009-05-03 17:18:57 +000024template<class U> class A; // expected-note{{previous template declaration is here}}
Douglas Gregorcd72ba92009-02-06 22:42:48 +000025
26template<int N> class A; // expected-error{{template parameter has a different kind in template redeclaration}}
27
Douglas Gregorcd72ba92009-02-06 22:42:48 +000028template<int N> class NonTypeTemplateParm;
29
30typedef int INT;
31
Chris Lattner810d3302009-02-19 23:45:49 +000032template<INT M> class NonTypeTemplateParm; // expected-note{{previous non-type template parameter with type 'INT' (aka 'int') is here}}
Douglas Gregorcd72ba92009-02-06 22:42:48 +000033
34template<long> class NonTypeTemplateParm; // expected-error{{template non-type parameter has a different type 'long' in template redeclaration}}
35
36template<template<typename T> class X> class TemplateTemplateParm;
37
38template<template<class> class Y> class TemplateTemplateParm; // expected-note{{previous template declaration is here}} \
39 // expected-note{{previous template template parameter is here}}
40
41template<typename> class TemplateTemplateParm; // expected-error{{template parameter has a different kind in template redeclaration}}
42
43template<template<typename T, int> class X> class TemplateTemplateParm; // expected-error{{too many template parameters in template template parameter redeclaration}}
44
Douglas Gregor71a57182009-06-22 23:20:33 +000045template<typename T>
46struct test {}; // expected-note{{previous definition}}
47
48template<typename T>
49struct test : T {}; // expected-error{{redefinition}}
50
Douglas Gregorcd72ba92009-02-06 22:42:48 +000051class X {
52public:
53 template<typename T> class C;
54};
55
56void f() {
Douglas Gregor866ad5d2009-11-05 20:02:41 +000057 template<typename T> class X; // expected-error{{expression}}
Douglas Gregorcd72ba92009-02-06 22:42:48 +000058}
Douglas Gregor4ebb7f32009-11-05 20:54:04 +000059
Larisse Voufo39a1e502013-08-06 01:03:05 +000060template<typename T> class X1 var; // expected-warning{{variable templates are a C++1y extension}} \
61 // expected-error {{variable has incomplete type 'class X1'}} \
62 // expected-note {{forward declaration of 'X1'}}
Douglas Gregorce40e2e2010-04-12 16:00:01 +000063
64namespace M {
65}
66
67template<typename T> class M::C3 { }; // expected-error{{out-of-line definition of 'C3' does not match any declaration in namespace 'M'}}
Nick Lewycky61478912010-11-08 23:29:42 +000068
69namespace PR8001 {
70 template<typename T1>
71 struct Foo {
72 template<typename T2> class Bar;
73 typedef Bar<T1> Baz;
74
75 template<typename T2>
76 struct Bar {
77 Bar() {}
78 };
79 };
80
81 void pr8001() {
82 Foo<int>::Baz x;
83 Foo<int>::Bar<int> y(x);
84 }
85}
Douglas Gregorfbf87522011-10-21 15:47:52 +000086
Douglas Gregor4109afa2011-11-07 17:43:18 +000087namespace rdar9676205 {
88 template <unsigned, class _Tp> class tuple_element;
89
90 template <class _T1, class _T2> class pair;
91
92 template <class _T1, class _T2>
93 class tuple_element<0, pair<_T1, _T2> >
94 {
95 template <class _Tp>
96 struct X
97 {
98 template <class _Up, bool = X<_Up>::value>
99 struct Y
100 : public X<_Up>,
101 public Y<_Up>
102 { };
103 };
104 };
105}
Richard Smith6483d222012-04-21 01:27:54 +0000106
107namespace redecl {
108 int A; // expected-note {{here}}
109 template<typename T> struct A; // expected-error {{different kind of symbol}}
110
Richard Smith9f2a7b22012-04-21 01:51:32 +0000111 int B; // expected-note {{here}}
Richard Smith6483d222012-04-21 01:27:54 +0000112 template<typename T> struct B { // expected-error {{different kind of symbol}}
113 };
114
115 template<typename T> struct F;
116 template<typename T> struct K;
117
Richard Smith9f2a7b22012-04-21 01:51:32 +0000118 int G, H; // expected-note {{here}}
Richard Smith6483d222012-04-21 01:27:54 +0000119
120 struct S {
121 int C; // expected-note {{here}}
122 template<typename T> struct C; // expected-error {{different kind of symbol}}
123
Richard Smith9f2a7b22012-04-21 01:51:32 +0000124 int D; // expected-note {{here}}
Richard Smith6483d222012-04-21 01:27:54 +0000125 template<typename T> struct D { // expected-error {{different kind of symbol}}
126 };
127
128 int E;
129 template<typename T> friend struct E { // expected-error {{cannot define a type in a friend}}
130 };
131
132 int F;
133 template<typename T> friend struct F; // ok, redecl::F
134
135 template<typename T> struct G; // ok
136
137 template<typename T> friend struct H; // expected-error {{different kind of symbol}}
138
139 int I, J, K;
140
141 struct U {
142 template<typename T> struct I; // ok
143 template<typename T> struct J { // ok
144 };
145 template<typename T> friend struct K; // ok, redecl::K
146 };
147 };
148}