blob: 7849bae4d571855eff1588eff9f785364c0ef642 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor551f48c2009-03-27 04:21:56 +00002class A;
3
4class S {
5public:
6 template<typename T> struct A {
7 struct Nested {
8 typedef T type;
9 };
10 };
11};
12
13int i;
14S::A<int>::Nested::type *ip = &i;
15
Douglas Gregorc3058332009-08-24 23:03:25 +000016template<typename T>
Douglas Gregor05396e22009-08-25 17:23:04 +000017struct Outer {
18 template<typename U>
19 class Inner0;
Douglas Gregorc3058332009-08-24 23:03:25 +000020
21 template<typename U>
Douglas Gregor05396e22009-08-25 17:23:04 +000022 class Inner1 {
23 struct ReallyInner;
24
25 T foo(U);
26 template<typename V> T bar(V);
Douglas Gregor495c35d2009-08-25 22:51:20 +000027 template<typename V> T* bar(V);
Douglas Gregorc131ebb2009-08-25 22:53:07 +000028
29 static T value1;
30 static U value2;
Douglas Gregorc3058332009-08-24 23:03:25 +000031 };
32};
33
Douglas Gregor05396e22009-08-25 17:23:04 +000034template<typename X>
35template<typename Y>
36class Outer<X>::Inner0 {
37public:
38 void f(X, Y);
39};
Douglas Gregorc3058332009-08-24 23:03:25 +000040
Douglas Gregor05396e22009-08-25 17:23:04 +000041template<typename X>
42template<typename Y>
43void Outer<X>::Inner0<Y>::f(X, Y) {
44}
45
46template<typename X>
47template<typename Y>
48struct Outer<X>::Inner1<Y>::ReallyInner {
Douglas Gregorbc047ba2009-08-25 22:54:02 +000049 static Y value3;
50
Douglas Gregor05396e22009-08-25 17:23:04 +000051 void g(X, Y);
52};
53
54template<typename X>
55template<typename Y>
56void Outer<X>::Inner1<Y>::ReallyInner::g(X, Y) {
57}
58
59template<typename X>
60template<typename Y>
61X Outer<X>::Inner1<Y>::foo(Y) {
62 return X();
63}
64
65template<typename X>
66template<typename Y>
67template<typename Z>
68X Outer<X>::Inner1<Y>::bar(Z) {
69 return X();
70}
Douglas Gregor495c35d2009-08-25 22:51:20 +000071
72template<typename X>
73template<typename Y>
74template<typename Z>
75X* Outer<X>::Inner1<Y>::bar(Z) {
76 return 0;
77}
Douglas Gregorc131ebb2009-08-25 22:53:07 +000078
79template<typename X>
80template<typename Y>
81X Outer<X>::Inner1<Y>::value1 = 0;
82
83template<typename X>
84template<typename Y>
85Y Outer<X>::Inner1<Y>::value2 = Y();
Douglas Gregorbc047ba2009-08-25 22:54:02 +000086
87template<typename X>
88template<typename Y>
89Y Outer<X>::Inner1<Y>::ReallyInner::value3 = Y();
Douglas Gregordacd4342009-08-26 00:04:55 +000090
91template<typename X>
92template<typename Y>
93Y Outer<X>::Inner1<Y*>::ReallyInner::value4; // expected-error{{Outer<X>::Inner1<Y *>::ReallyInner::}}
Douglas Gregor1cdcc572009-09-10 00:12:48 +000094
95
96template<typename T>
97struct X0 { };
98
99template<typename T>
100struct X0<T*> {
101 template<typename U>
102 void f(U u = T()) { }
103};
Douglas Gregor33642df2009-10-23 23:25:44 +0000104
105// PR5103
106template<typename>
107struct X1 {
108 template<typename, bool = false> struct B { };
109};
110template struct X1<int>::B<bool>;
Douglas Gregor9106ef72009-11-11 16:58:32 +0000111
112// Template template parameters
113template<typename T>
114struct X2 {
115 template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}} \
116 // expected-note{{previous non-type template}}
117 struct Inner { };
118};
119
120template<typename T,
121 int Value> // expected-note{{template non-type parameter}}
122 struct X2_arg;
123
124X2<int>::Inner<X2_arg> x2i1;
Douglas Gregor9148c3f2009-11-11 19:13:48 +0000125X2<float> x2a; // expected-note{{instantiation}}
Douglas Gregor9106ef72009-11-11 16:58:32 +0000126X2<long>::Inner<X2_arg> x2i3; // expected-error{{template template argument has different}}
127
Douglas Gregorf2503652011-09-21 14:40:46 +0000128namespace PR10896 {
129 template<typename TN>
130 class Foo {
Douglas Gregor9106ef72009-11-11 16:58:32 +0000131
Douglas Gregorf2503652011-09-21 14:40:46 +0000132 public:
133 void foo() {}
134 private:
135
136 template<typename T>
137 T SomeField; // expected-error {{member 'SomeField' declared as a template}}
138 };
139
140 void g() {
141 Foo<int> f;
142 f.foo();
143 }
144}
Douglas Gregorea9f54a2011-11-01 21:35:16 +0000145
146namespace PR10924 {
147 template< class Topology, class ctype >
148 struct ReferenceElement
149 {
150 };
151
152 template< class Topology, class ctype >
153 template< int codim >
154 class ReferenceElement< Topology, ctype > :: BaryCenterArray // expected-error{{out-of-line definition of 'BaryCenterArray' does not match any declaration in 'ReferenceElement<Topology, ctype>'}}
155 {
156 };
157}