1 // RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify -std=c++11 %s
2 
3 template <class T>
4 class A {
foo()5    void foo() {
6        undeclared();
7    }
8    void foo2();
9 };
10 
11 template <class T>
12 class B {
foo4()13    void foo4() { } // expected-note {{previous definition is here}}
foo4()14    void foo4() { } // expected-error {{class member cannot be redeclared}}
foo5()15    void foo5() { } // expected-note {{previous definition is here}}
16 
foo3()17    friend void foo3() {
18        undeclared();
19    }
20 };
21 
22 
23 template <class T>
foo5()24 void B<T>::foo5() { // expected-error {{redefinition of 'foo5'}}
25 }
26 
27 template <class T>
foo2()28 void A<T>::foo2() {
29     undeclared();
30 }
31 
32 
33 template <class T>
foo3()34 void foo3() {
35    undeclared();
36 }
37 
38 template void A<int>::foo2();
39 
40 
undeclared()41 void undeclared()
42 {
43 
44 }
45 
foo5()46 template <class T> void foo5() {} //expected-note {{previous definition is here}}
foo5()47 template <class T> void foo5() {} // expected-error {{redefinition of 'foo5'}}
48 
49 
50 
51 
52 namespace PR11931 {
53 
54 template <typename RunType>
55 struct BindState;
56 
57   template<>
58 struct BindState<void(void*)> {
RunPR11931::BindState59   static void Run() { }
60 };
61 
62 class Callback {
63 public:
64   typedef void RunType();
65 
66   template <typename RunType>
Callback(BindState<RunType> bind_state)67   Callback(BindState<RunType> bind_state) {
68     BindState<RunType>::Run();
69   }
70 };
71 
72 
Bind()73 Callback Bind() {
74   return Callback(BindState<void(void*)>());
75 }
76 
77 }
78 
79 namespace rdar11700604 {
80   template<typename T> void foo() = delete;
81 
82   struct X {
83     X() = default;
84 
85     template<typename T> void foo() = delete;
86   };
87 }
88 
89 namespace PR17334 {
90 
91 template <typename = void> struct ArrayRef {
ArrayRefPR17334::ArrayRef92   constexpr ArrayRef() {}
93 };
CreateConstInBoundsGEP2_32()94 template <typename = void> void CreateConstInBoundsGEP2_32() {
95   ArrayRef<> IdxList;
96 }
LLVMBuildStructGEP()97 void LLVMBuildStructGEP() { CreateConstInBoundsGEP2_32(); }
98 
99 }
100 
101 namespace PR17661 {
102 template <typename T>
Fun(T A)103 constexpr T Fun(T A) { return T(0); }
104 
105 constexpr int Var = Fun(20);
106 }
107 
108 template <typename T>
invalidTrailingRetType()109 auto invalidTrailingRetType() -> Bogus {} // expected-error {{unknown type name 'Bogus'}}
110 
111 namespace PR19613 {
112 
113 struct HeapTypeConfig {
114   static void from_bitset();
115 };
116 
117 template <class Config>
118 struct TypeImpl  {
119   struct BitsetType;
120 
AnyPR19613::TypeImpl121   static void Any() {
122     BitsetType::New();
123   }
124 };
125 
126 template<class Config>
127 struct TypeImpl<Config>::BitsetType {
NewPR19613::TypeImpl::BitsetType128   static void New() {
129     Config::from_bitset();
130   }
131 };
132 
f()133 static void f() {
134   TypeImpl<HeapTypeConfig>::Any();
135 }
136 
137 template<typename A> struct S {
138   template<typename B> struct T;
139 };
140 template<typename A> template<typename B> struct S<A>::T {
141   template<typename C, typename D> struct U;
142   template<typename C> struct U<C, C> {
fPR19613::S::T::U143     template<typename E> static int f() {
144       return sizeof(A) + sizeof(B) + sizeof(C) + sizeof(E);
145     }
146   };
147 };
148 
g()149 static void g() {
150   S<int>::T<int>::U<int,int>::f<int>();
151 }
152 
153 template<typename T> struct SS {
154   template<typename U> struct X;
155   template<typename U> struct X<U*>;
156 };
157 template<typename T> template<typename U> struct SS<T>::X<U*> {
fPR19613::SS::X158   static int f() {
159     return sizeof(T) + sizeof(U);
160   }
161 };
162 
h()163 static void h() {
164   SS<int>::X<int*>::f();
165 }
166 
167 }
168 
169 struct PR38460 {
170   template <typename>
171   struct T {
fooPR38460::T172     static void foo() {
173       struct U {
174         void dummy() {
175           use_delayed_identifier();
176         }
177       };
178     }
179   };
180 };
181 void use_delayed_identifier();
trigger_PR38460()182 void trigger_PR38460() {
183   PR38460::T<int>::foo();
184 }
185 
186 template <typename> struct PR38460_2 {
187   struct p {
188     struct G {
operator ()PR38460_2::p::G189       bool operator()(int) {}
190     };
191   };
asPR38460_2192   static void as() {
193     typename p::G g;
194     g(0);
195   }
196 };
197 template struct PR38460_2<int>;
198