blob: e65da2b312f63c2736dd2098f8afa777e852780a [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregorddc29e12009-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
Douglas Gregored4ec8f2009-05-03 17:18:57 +000017template<class U> class A; // expected-note{{previous template declaration is here}}
Douglas Gregorddc29e12009-02-06 22:42:48 +000018
19template<int N> class A; // expected-error{{template parameter has a different kind in template redeclaration}}
20
Douglas Gregorddc29e12009-02-06 22:42:48 +000021template<int N> class NonTypeTemplateParm;
22
23typedef int INT;
24
Chris Lattnerd0344a42009-02-19 23:45:49 +000025template<INT M> class NonTypeTemplateParm; // expected-note{{previous non-type template parameter with type 'INT' (aka 'int') is here}}
Douglas Gregorddc29e12009-02-06 22:42:48 +000026
27template<long> class NonTypeTemplateParm; // expected-error{{template non-type parameter has a different type 'long' in template redeclaration}}
28
29template<template<typename T> class X> class TemplateTemplateParm;
30
31template<template<class> class Y> class TemplateTemplateParm; // expected-note{{previous template declaration is here}} \
32 // expected-note{{previous template template parameter is here}}
33
34template<typename> class TemplateTemplateParm; // expected-error{{template parameter has a different kind in template redeclaration}}
35
36template<template<typename T, int> class X> class TemplateTemplateParm; // expected-error{{too many template parameters in template template parameter redeclaration}}
37
Douglas Gregor4c4f7cb2009-06-22 23:20:33 +000038template<typename T>
39struct test {}; // expected-note{{previous definition}}
40
41template<typename T>
42struct test : T {}; // expected-error{{redefinition}}
43
Douglas Gregorddc29e12009-02-06 22:42:48 +000044class X {
45public:
46 template<typename T> class C;
47};
48
49void f() {
Douglas Gregorc2f38822009-11-05 20:02:41 +000050 template<typename T> class X; // expected-error{{expression}}
Douglas Gregorddc29e12009-02-06 22:42:48 +000051}
Douglas Gregorc7621a62009-11-05 20:54:04 +000052
Larisse Voufoef4579c2013-08-06 01:03:05 +000053template<typename T> class X1 var; // expected-warning{{variable templates are a C++1y extension}} \
54 // expected-error {{variable has incomplete type 'class X1'}} \
55 // expected-note {{forward declaration of 'X1'}}
Douglas Gregor57265e32010-04-12 16:00:01 +000056
57namespace M {
58}
59
60template<typename T> class M::C3 { }; // expected-error{{out-of-line definition of 'C3' does not match any declaration in namespace 'M'}}
Nick Lewycky37574f52010-11-08 23:29:42 +000061
62namespace PR8001 {
63 template<typename T1>
64 struct Foo {
65 template<typename T2> class Bar;
66 typedef Bar<T1> Baz;
67
68 template<typename T2>
69 struct Bar {
70 Bar() {}
71 };
72 };
73
74 void pr8001() {
75 Foo<int>::Baz x;
76 Foo<int>::Bar<int> y(x);
77 }
78}
Douglas Gregor95e55102011-10-21 15:47:52 +000079
Douglas Gregor2c1227c2011-11-07 17:43:18 +000080namespace rdar9676205 {
81 template <unsigned, class _Tp> class tuple_element;
82
83 template <class _T1, class _T2> class pair;
84
85 template <class _T1, class _T2>
86 class tuple_element<0, pair<_T1, _T2> >
87 {
88 template <class _Tp>
89 struct X
90 {
91 template <class _Up, bool = X<_Up>::value>
92 struct Y
93 : public X<_Up>,
94 public Y<_Up>
95 { };
96 };
97 };
98}
Richard Smith71c598f2012-04-21 01:27:54 +000099
100namespace redecl {
101 int A; // expected-note {{here}}
102 template<typename T> struct A; // expected-error {{different kind of symbol}}
103
Richard Smith227e9f62012-04-21 01:51:32 +0000104 int B; // expected-note {{here}}
Richard Smith71c598f2012-04-21 01:27:54 +0000105 template<typename T> struct B { // expected-error {{different kind of symbol}}
106 };
107
108 template<typename T> struct F;
109 template<typename T> struct K;
110
Richard Smith227e9f62012-04-21 01:51:32 +0000111 int G, H; // expected-note {{here}}
Richard Smith71c598f2012-04-21 01:27:54 +0000112
113 struct S {
114 int C; // expected-note {{here}}
115 template<typename T> struct C; // expected-error {{different kind of symbol}}
116
Richard Smith227e9f62012-04-21 01:51:32 +0000117 int D; // expected-note {{here}}
Richard Smith71c598f2012-04-21 01:27:54 +0000118 template<typename T> struct D { // expected-error {{different kind of symbol}}
119 };
120
121 int E;
122 template<typename T> friend struct E { // expected-error {{cannot define a type in a friend}}
123 };
124
125 int F;
126 template<typename T> friend struct F; // ok, redecl::F
127
128 template<typename T> struct G; // ok
129
130 template<typename T> friend struct H; // expected-error {{different kind of symbol}}
131
132 int I, J, K;
133
134 struct U {
135 template<typename T> struct I; // ok
136 template<typename T> struct J { // ok
137 };
138 template<typename T> friend struct K; // ok, redecl::K
139 };
140 };
141}