1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc class A;
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc class S {
5*f4a2713aSLionel Sambuc public:
6*f4a2713aSLionel Sambuc template<typename T> struct A {
7*f4a2713aSLionel Sambuc struct Nested {
8*f4a2713aSLionel Sambuc typedef T type;
9*f4a2713aSLionel Sambuc };
10*f4a2713aSLionel Sambuc };
11*f4a2713aSLionel Sambuc };
12*f4a2713aSLionel Sambuc
13*f4a2713aSLionel Sambuc int i;
14*f4a2713aSLionel Sambuc S::A<int>::Nested::type *ip = &i;
15*f4a2713aSLionel Sambuc
16*f4a2713aSLionel Sambuc template<typename T>
17*f4a2713aSLionel Sambuc struct Outer {
18*f4a2713aSLionel Sambuc template<typename U>
19*f4a2713aSLionel Sambuc class Inner0;
20*f4a2713aSLionel Sambuc
21*f4a2713aSLionel Sambuc template<typename U>
22*f4a2713aSLionel Sambuc class Inner1 {
23*f4a2713aSLionel Sambuc struct ReallyInner;
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambuc T foo(U);
26*f4a2713aSLionel Sambuc template<typename V> T bar(V);
27*f4a2713aSLionel Sambuc template<typename V> T* bar(V);
28*f4a2713aSLionel Sambuc
29*f4a2713aSLionel Sambuc static T value1;
30*f4a2713aSLionel Sambuc static U value2;
31*f4a2713aSLionel Sambuc };
32*f4a2713aSLionel Sambuc };
33*f4a2713aSLionel Sambuc
34*f4a2713aSLionel Sambuc template<typename X>
35*f4a2713aSLionel Sambuc template<typename Y>
36*f4a2713aSLionel Sambuc class Outer<X>::Inner0 {
37*f4a2713aSLionel Sambuc public:
38*f4a2713aSLionel Sambuc void f(X, Y);
39*f4a2713aSLionel Sambuc };
40*f4a2713aSLionel Sambuc
41*f4a2713aSLionel Sambuc template<typename X>
42*f4a2713aSLionel Sambuc template<typename Y>
f(X,Y)43*f4a2713aSLionel Sambuc void Outer<X>::Inner0<Y>::f(X, Y) {
44*f4a2713aSLionel Sambuc }
45*f4a2713aSLionel Sambuc
46*f4a2713aSLionel Sambuc template<typename X>
47*f4a2713aSLionel Sambuc template<typename Y>
48*f4a2713aSLionel Sambuc struct Outer<X>::Inner1<Y>::ReallyInner {
49*f4a2713aSLionel Sambuc static Y value3;
50*f4a2713aSLionel Sambuc
51*f4a2713aSLionel Sambuc void g(X, Y);
52*f4a2713aSLionel Sambuc };
53*f4a2713aSLionel Sambuc
54*f4a2713aSLionel Sambuc template<typename X>
55*f4a2713aSLionel Sambuc template<typename Y>
g(X,Y)56*f4a2713aSLionel Sambuc void Outer<X>::Inner1<Y>::ReallyInner::g(X, Y) {
57*f4a2713aSLionel Sambuc }
58*f4a2713aSLionel Sambuc
59*f4a2713aSLionel Sambuc template<typename X>
60*f4a2713aSLionel Sambuc template<typename Y>
foo(Y)61*f4a2713aSLionel Sambuc X Outer<X>::Inner1<Y>::foo(Y) {
62*f4a2713aSLionel Sambuc return X();
63*f4a2713aSLionel Sambuc }
64*f4a2713aSLionel Sambuc
65*f4a2713aSLionel Sambuc template<typename X>
66*f4a2713aSLionel Sambuc template<typename Y>
67*f4a2713aSLionel Sambuc template<typename Z>
bar(Z)68*f4a2713aSLionel Sambuc X Outer<X>::Inner1<Y>::bar(Z) {
69*f4a2713aSLionel Sambuc return X();
70*f4a2713aSLionel Sambuc }
71*f4a2713aSLionel Sambuc
72*f4a2713aSLionel Sambuc template<typename X>
73*f4a2713aSLionel Sambuc template<typename Y>
74*f4a2713aSLionel Sambuc template<typename Z>
bar(Z)75*f4a2713aSLionel Sambuc X* Outer<X>::Inner1<Y>::bar(Z) {
76*f4a2713aSLionel Sambuc return 0;
77*f4a2713aSLionel Sambuc }
78*f4a2713aSLionel Sambuc
79*f4a2713aSLionel Sambuc template<typename X>
80*f4a2713aSLionel Sambuc template<typename Y>
81*f4a2713aSLionel Sambuc X Outer<X>::Inner1<Y>::value1 = 0;
82*f4a2713aSLionel Sambuc
83*f4a2713aSLionel Sambuc template<typename X>
84*f4a2713aSLionel Sambuc template<typename Y>
85*f4a2713aSLionel Sambuc Y Outer<X>::Inner1<Y>::value2 = Y();
86*f4a2713aSLionel Sambuc
87*f4a2713aSLionel Sambuc template<typename X>
88*f4a2713aSLionel Sambuc template<typename Y>
89*f4a2713aSLionel Sambuc Y Outer<X>::Inner1<Y>::ReallyInner::value3 = Y();
90*f4a2713aSLionel Sambuc
91*f4a2713aSLionel Sambuc template<typename X>
92*f4a2713aSLionel Sambuc template<typename Y>
93*f4a2713aSLionel Sambuc Y Outer<X>::Inner1<Y*>::ReallyInner::value4; // expected-error{{Outer<X>::Inner1<Y *>::ReallyInner::}}
94*f4a2713aSLionel Sambuc
95*f4a2713aSLionel Sambuc
96*f4a2713aSLionel Sambuc template<typename T>
97*f4a2713aSLionel Sambuc struct X0 { };
98*f4a2713aSLionel Sambuc
99*f4a2713aSLionel Sambuc template<typename T>
100*f4a2713aSLionel Sambuc struct X0<T*> {
101*f4a2713aSLionel Sambuc template<typename U>
fX0102*f4a2713aSLionel Sambuc void f(U u = T()) { }
103*f4a2713aSLionel Sambuc };
104*f4a2713aSLionel Sambuc
105*f4a2713aSLionel Sambuc // PR5103
106*f4a2713aSLionel Sambuc template<typename>
107*f4a2713aSLionel Sambuc struct X1 {
108*f4a2713aSLionel Sambuc template<typename, bool = false> struct B { };
109*f4a2713aSLionel Sambuc };
110*f4a2713aSLionel Sambuc template struct X1<int>::B<bool>;
111*f4a2713aSLionel Sambuc
112*f4a2713aSLionel Sambuc // Template template parameters
113*f4a2713aSLionel Sambuc template<typename T>
114*f4a2713aSLionel Sambuc struct X2 {
115*f4a2713aSLionel Sambuc template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}} \
116*f4a2713aSLionel Sambuc // expected-note{{previous non-type template}}
117*f4a2713aSLionel Sambuc struct Inner { };
118*f4a2713aSLionel Sambuc };
119*f4a2713aSLionel Sambuc
120*f4a2713aSLionel Sambuc template<typename T,
121*f4a2713aSLionel Sambuc int Value> // expected-note{{template non-type parameter}}
122*f4a2713aSLionel Sambuc struct X2_arg;
123*f4a2713aSLionel Sambuc
124*f4a2713aSLionel Sambuc X2<int>::Inner<X2_arg> x2i1;
125*f4a2713aSLionel Sambuc X2<float> x2a; // expected-note{{instantiation}}
126*f4a2713aSLionel Sambuc X2<long>::Inner<X2_arg> x2i3; // expected-error{{template template argument has different}}
127*f4a2713aSLionel Sambuc
128*f4a2713aSLionel Sambuc namespace PR10896 {
129*f4a2713aSLionel Sambuc template<typename TN>
130*f4a2713aSLionel Sambuc class Foo {
131*f4a2713aSLionel Sambuc
132*f4a2713aSLionel Sambuc public:
foo()133*f4a2713aSLionel Sambuc void foo() {}
134*f4a2713aSLionel Sambuc private:
135*f4a2713aSLionel Sambuc
136*f4a2713aSLionel Sambuc template<typename T>
137*f4a2713aSLionel Sambuc T SomeField; // expected-error {{member 'SomeField' declared as a template}}
138*f4a2713aSLionel Sambuc template<> int SomeField2; // expected-error {{extraneous 'template<>' in declaration of member 'SomeField2'}}
139*f4a2713aSLionel Sambuc };
140*f4a2713aSLionel Sambuc
g()141*f4a2713aSLionel Sambuc void g() {
142*f4a2713aSLionel Sambuc Foo<int> f;
143*f4a2713aSLionel Sambuc f.foo();
144*f4a2713aSLionel Sambuc }
145*f4a2713aSLionel Sambuc }
146*f4a2713aSLionel Sambuc
147*f4a2713aSLionel Sambuc namespace PR10924 {
148*f4a2713aSLionel Sambuc template< class Topology, class ctype >
149*f4a2713aSLionel Sambuc struct ReferenceElement
150*f4a2713aSLionel Sambuc {
151*f4a2713aSLionel Sambuc };
152*f4a2713aSLionel Sambuc
153*f4a2713aSLionel Sambuc template< class Topology, class ctype >
154*f4a2713aSLionel Sambuc template< int codim >
155*f4a2713aSLionel Sambuc class ReferenceElement< Topology, ctype > :: BaryCenterArray // expected-error{{out-of-line definition of 'BaryCenterArray' does not match any declaration in 'ReferenceElement<Topology, ctype>'}}
156*f4a2713aSLionel Sambuc {
157*f4a2713aSLionel Sambuc };
158*f4a2713aSLionel Sambuc }
159*f4a2713aSLionel Sambuc
160*f4a2713aSLionel Sambuc class Outer1 {
161*f4a2713aSLionel Sambuc template <typename T> struct X;
func()162*f4a2713aSLionel Sambuc template <typename T> int X<T>::func() {} // expected-error{{out-of-line definition of 'func' from class 'X<T>' without definition}}
163*f4a2713aSLionel Sambuc };
164