xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/DelayedTemplateParsing.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify -std=c++11 %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc template <class T>
4f4a2713aSLionel Sambuc class A {
foo()5f4a2713aSLionel Sambuc    void foo() {
6f4a2713aSLionel Sambuc        undeclared();
7f4a2713aSLionel Sambuc    }
8f4a2713aSLionel Sambuc    void foo2();
9f4a2713aSLionel Sambuc };
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc template <class T>
12f4a2713aSLionel Sambuc class B {
foo4()13f4a2713aSLionel Sambuc    void foo4() { } // expected-note {{previous definition is here}}  expected-note {{previous definition is here}}
foo4()14f4a2713aSLionel Sambuc    void foo4() { } // expected-error {{class member cannot be redeclared}} expected-error {{redefinition of 'foo4'}}
foo5()15f4a2713aSLionel Sambuc    void foo5() { } // expected-note {{previous definition is here}}
16f4a2713aSLionel Sambuc 
foo3()17f4a2713aSLionel Sambuc    friend void foo3() {
18f4a2713aSLionel Sambuc        undeclared();
19f4a2713aSLionel Sambuc    }
20f4a2713aSLionel Sambuc };
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc template <class T>
foo5()24f4a2713aSLionel Sambuc void B<T>::foo5() { // expected-error {{redefinition of 'foo5'}}
25f4a2713aSLionel Sambuc }
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc template <class T>
foo2()28f4a2713aSLionel Sambuc void A<T>::foo2() {
29f4a2713aSLionel Sambuc     undeclared();
30f4a2713aSLionel Sambuc }
31f4a2713aSLionel Sambuc 
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc template <class T>
foo3()34f4a2713aSLionel Sambuc void foo3() {
35f4a2713aSLionel Sambuc    undeclared();
36f4a2713aSLionel Sambuc }
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc template void A<int>::foo2();
39f4a2713aSLionel Sambuc 
40f4a2713aSLionel Sambuc 
undeclared()41f4a2713aSLionel Sambuc void undeclared()
42f4a2713aSLionel Sambuc {
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc }
45f4a2713aSLionel Sambuc 
foo5()46f4a2713aSLionel Sambuc template <class T> void foo5() {} //expected-note {{previous definition is here}}
foo5()47f4a2713aSLionel Sambuc template <class T> void foo5() {} // expected-error {{redefinition of 'foo5'}}
48f4a2713aSLionel Sambuc 
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc 
51f4a2713aSLionel Sambuc namespace Inner_Outer_same_template_param_name {
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc template <class T>
54f4a2713aSLionel Sambuc class Outmost {
55f4a2713aSLionel Sambuc public:
56f4a2713aSLionel Sambuc     template <class T>
57f4a2713aSLionel Sambuc     class Inner {
58f4a2713aSLionel Sambuc     public:
f()59f4a2713aSLionel Sambuc         void f() {
60f4a2713aSLionel Sambuc             T* var;
61f4a2713aSLionel Sambuc         }
62f4a2713aSLionel Sambuc    };
63f4a2713aSLionel Sambuc };
64f4a2713aSLionel Sambuc 
65f4a2713aSLionel Sambuc }
66f4a2713aSLionel Sambuc 
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc namespace PR11931 {
69f4a2713aSLionel Sambuc 
70f4a2713aSLionel Sambuc template <typename RunType>
71f4a2713aSLionel Sambuc struct BindState;
72f4a2713aSLionel Sambuc 
73f4a2713aSLionel Sambuc   template<>
74f4a2713aSLionel Sambuc struct BindState<void(void*)> {
RunPR11931::BindState75f4a2713aSLionel Sambuc   static void Run() { }
76f4a2713aSLionel Sambuc };
77f4a2713aSLionel Sambuc 
78f4a2713aSLionel Sambuc class Callback {
79f4a2713aSLionel Sambuc public:
80f4a2713aSLionel Sambuc   typedef void RunType();
81f4a2713aSLionel Sambuc 
82f4a2713aSLionel Sambuc   template <typename RunType>
Callback(BindState<RunType> bind_state)83f4a2713aSLionel Sambuc   Callback(BindState<RunType> bind_state) {
84f4a2713aSLionel Sambuc     BindState<RunType>::Run();
85f4a2713aSLionel Sambuc   }
86f4a2713aSLionel Sambuc };
87f4a2713aSLionel Sambuc 
88f4a2713aSLionel Sambuc 
Bind()89f4a2713aSLionel Sambuc Callback Bind() {
90f4a2713aSLionel Sambuc   return Callback(BindState<void(void*)>());
91f4a2713aSLionel Sambuc }
92f4a2713aSLionel Sambuc 
93f4a2713aSLionel Sambuc }
94f4a2713aSLionel Sambuc 
95f4a2713aSLionel Sambuc namespace rdar11700604 {
96f4a2713aSLionel Sambuc   template<typename T> void foo() = delete;
97f4a2713aSLionel Sambuc 
98f4a2713aSLionel Sambuc   struct X {
99f4a2713aSLionel Sambuc     X() = default;
100f4a2713aSLionel Sambuc 
101f4a2713aSLionel Sambuc     template<typename T> void foo() = delete;
102f4a2713aSLionel Sambuc   };
103f4a2713aSLionel Sambuc }
104f4a2713aSLionel Sambuc 
105f4a2713aSLionel Sambuc namespace PR17334 {
106f4a2713aSLionel Sambuc 
107f4a2713aSLionel Sambuc template <typename = void> struct ArrayRef {
ArrayRefPR17334::ArrayRef108f4a2713aSLionel Sambuc   constexpr ArrayRef() {}
109f4a2713aSLionel Sambuc };
CreateConstInBoundsGEP2_32()110f4a2713aSLionel Sambuc template <typename = void> void CreateConstInBoundsGEP2_32() {
111f4a2713aSLionel Sambuc   ArrayRef<> IdxList;
112f4a2713aSLionel Sambuc }
LLVMBuildStructGEP()113f4a2713aSLionel Sambuc void LLVMBuildStructGEP() { CreateConstInBoundsGEP2_32(); }
114f4a2713aSLionel Sambuc 
115f4a2713aSLionel Sambuc }
116f4a2713aSLionel Sambuc 
117f4a2713aSLionel Sambuc namespace PR17661 {
118f4a2713aSLionel Sambuc template <typename T>
Fun(T A)119f4a2713aSLionel Sambuc constexpr T Fun(T A) { return T(0); }
120f4a2713aSLionel Sambuc 
121f4a2713aSLionel Sambuc constexpr int Var = Fun(20);
122f4a2713aSLionel Sambuc }
123f4a2713aSLionel Sambuc 
124*0a6a1f1dSLionel Sambuc template <typename T>
invalidTrailingRetType()125*0a6a1f1dSLionel Sambuc auto invalidTrailingRetType() -> Bogus {} // expected-error {{unknown type name 'Bogus'}}
126*0a6a1f1dSLionel Sambuc 
127*0a6a1f1dSLionel Sambuc namespace PR19613 {
128*0a6a1f1dSLionel Sambuc 
129*0a6a1f1dSLionel Sambuc struct HeapTypeConfig {
130*0a6a1f1dSLionel Sambuc   static void from_bitset();
131*0a6a1f1dSLionel Sambuc };
132*0a6a1f1dSLionel Sambuc 
133*0a6a1f1dSLionel Sambuc template <class Config>
134*0a6a1f1dSLionel Sambuc struct TypeImpl  {
135*0a6a1f1dSLionel Sambuc   struct BitsetType;
136*0a6a1f1dSLionel Sambuc 
AnyPR19613::TypeImpl137*0a6a1f1dSLionel Sambuc   static void Any() {
138*0a6a1f1dSLionel Sambuc     BitsetType::New();
139*0a6a1f1dSLionel Sambuc   }
140*0a6a1f1dSLionel Sambuc };
141*0a6a1f1dSLionel Sambuc 
142*0a6a1f1dSLionel Sambuc template<class Config>
143*0a6a1f1dSLionel Sambuc struct TypeImpl<Config>::BitsetType {
NewPR19613::TypeImpl::BitsetType144*0a6a1f1dSLionel Sambuc   static void New() {
145*0a6a1f1dSLionel Sambuc     Config::from_bitset();
146*0a6a1f1dSLionel Sambuc   }
147*0a6a1f1dSLionel Sambuc };
148*0a6a1f1dSLionel Sambuc 
f()149*0a6a1f1dSLionel Sambuc static void f() {
150*0a6a1f1dSLionel Sambuc   TypeImpl<HeapTypeConfig>::Any();
151*0a6a1f1dSLionel Sambuc }
152*0a6a1f1dSLionel Sambuc 
153*0a6a1f1dSLionel Sambuc template<typename A> struct S {
154*0a6a1f1dSLionel Sambuc   template<typename B> struct T;
155*0a6a1f1dSLionel Sambuc };
156*0a6a1f1dSLionel Sambuc template<typename A> template<typename B> struct S<A>::T {
157*0a6a1f1dSLionel Sambuc   template<typename C, typename D> struct U;
158*0a6a1f1dSLionel Sambuc   template<typename C> struct U<C, C> {
fPR19613::S::T::U159*0a6a1f1dSLionel Sambuc     template<typename E> static int f() {
160*0a6a1f1dSLionel Sambuc       return sizeof(A) + sizeof(B) + sizeof(C) + sizeof(E);
161*0a6a1f1dSLionel Sambuc     }
162*0a6a1f1dSLionel Sambuc   };
163*0a6a1f1dSLionel Sambuc };
164*0a6a1f1dSLionel Sambuc 
g()165*0a6a1f1dSLionel Sambuc static void g() {
166*0a6a1f1dSLionel Sambuc   S<int>::T<int>::U<int,int>::f<int>();
167*0a6a1f1dSLionel Sambuc }
168*0a6a1f1dSLionel Sambuc 
169*0a6a1f1dSLionel Sambuc template<typename T> struct SS {
170*0a6a1f1dSLionel Sambuc   template<typename U> struct X;
171*0a6a1f1dSLionel Sambuc   template<typename U> struct X<U*>;
172*0a6a1f1dSLionel Sambuc };
173*0a6a1f1dSLionel Sambuc template<typename T> template<typename U> struct SS<T>::X<U*> {
fPR19613::SS::X174*0a6a1f1dSLionel Sambuc   static int f() {
175*0a6a1f1dSLionel Sambuc     return sizeof(T) + sizeof(U);
176*0a6a1f1dSLionel Sambuc   }
177*0a6a1f1dSLionel Sambuc };
178*0a6a1f1dSLionel Sambuc 
h()179*0a6a1f1dSLionel Sambuc static void h() {
180*0a6a1f1dSLionel Sambuc   SS<int>::X<int*>::f();
181*0a6a1f1dSLionel Sambuc }
182*0a6a1f1dSLionel Sambuc 
183*0a6a1f1dSLionel Sambuc }
184