1 // RUN: %clang_cc1 -triple i686-win32             -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DMS %s
2 // RUN: %clang_cc1 -triple x86_64-win32           -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DMS %s
3 // RUN: %clang_cc1 -triple i686-mingw32           -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template %s
4 // RUN: %clang_cc1 -triple x86_64-mingw32         -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template %s
5 // RUN: %clang_cc1 -triple i686-windows-itanium   -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
6 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DWI %s
7 // RUN: %clang_cc1 -triple x86_64-scei-ps4        -fsyntax-only -fdeclspec      -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
8 // RUN: %clang_cc1 -triple x86_64-sie-ps5         -fsyntax-only -fdeclspec      -verify -std=c++1y -Wunsupported-dll-base-class-template -DWI %s
9 
10 // Helper structs to make templates more expressive.
11 struct ImplicitInst_Exported {};
12 struct ExplicitDecl_Exported {};
13 struct ExplicitInst_Exported {};
14 struct ExplicitSpec_Exported {};
15 struct ExplicitSpec_Def_Exported {};
16 struct ExplicitSpec_InlineDef_Exported {};
17 struct ExplicitSpec_NotExported {};
18 namespace { struct Internal {}; }
19 struct External { int v; };
20 
21 
22 // Invalid usage.
23 __declspec(dllexport) typedef int typedef1;
24 // expected-warning@-1{{'dllexport' attribute only applies to functions, variables, classes, and Objective-C interfaces}}
25 typedef __declspec(dllexport) int typedef2;
26 // expected-warning@-1{{'dllexport' attribute only applies to}}
27 typedef int __declspec(dllexport) typedef3;
28 // expected-warning@-1{{'dllexport' attribute only applies to}}
29 typedef __declspec(dllexport) void (*FunTy)();
30 // expected-warning@-1{{'dllexport' attribute only applies to}}
31 enum __declspec(dllexport) Enum {};
32 // expected-warning@-1{{'dllexport' attribute only applies to}}
33 #if __has_feature(cxx_strong_enums)
34 enum class __declspec(dllexport) EnumClass {};
35 // expected-warning@-1{{'dllexport' attribute only applies to}}
36 #endif
37 
38 
39 
40 //===----------------------------------------------------------------------===//
41 // Globals
42 //===----------------------------------------------------------------------===//
43 
44 // Export declaration.
45 __declspec(dllexport) extern int ExternGlobalDecl;
46 
47 // dllexport implies a definition.
48 __declspec(dllexport) int GlobalDef;
49 
50 // Export definition.
51 __declspec(dllexport) int GlobalInit1 = 1;
52 int __declspec(dllexport) GlobalInit2 = 1;
53 
54 // Declare, then export definition.
55 __declspec(dllexport) extern int GlobalDeclInit;
56 int GlobalDeclInit = 1;
57 
58 // Redeclarations
59 __declspec(dllexport) extern int GlobalRedecl1;
60 __declspec(dllexport)        int GlobalRedecl1;
61 
62 __declspec(dllexport) extern int GlobalRedecl2;
63                              int GlobalRedecl2;
64 
65                       extern int GlobalRedecl3; // expected-note{{previous declaration is here}}
66 __declspec(dllexport) extern int GlobalRedecl3; // expected-warning{{redeclaration of 'GlobalRedecl3' should not add 'dllexport' attribute}}
67 
68 extern "C" {
69                       extern int GlobalRedecl4; // expected-note{{previous declaration is here}}
70 __declspec(dllexport) extern int GlobalRedecl4; // expected-warning{{redeclaration of 'GlobalRedecl4' should not add 'dllexport' attribute}}
71 }
72 
73 // External linkage is required.
74 __declspec(dllexport) static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllexport'}}
75 __declspec(dllexport) Internal InternalTypeGlobal; // expected-error{{'InternalTypeGlobal' must have external linkage when declared 'dllexport'}}
76 #ifndef MS
77 namespace    { __declspec(dllexport) int InternalGlobal; } // expected-error{{'(anonymous namespace)::InternalGlobal' must have external linkage when declared 'dllexport'}}
78 #endif
79 namespace ns { __declspec(dllexport) int ExternalGlobal; }
80 
81 __declspec(dllexport) auto InternalAutoTypeGlobal = Internal(); // expected-error{{'InternalAutoTypeGlobal' must have external linkage when declared 'dllexport'}}
82 __declspec(dllexport) auto ExternalAutoTypeGlobal = External();
83 
84 // Thread local variables are invalid.
85 __declspec(dllexport) __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllexport'}}
86 // But a static local TLS var in an export function is OK.
ExportedInlineWithThreadLocal()87 inline void __declspec(dllexport) ExportedInlineWithThreadLocal() {
88   static __thread int OK; // no-error
89 }
90 
91 // Export in local scope.
functionScope()92 void functionScope() {
93   __declspec(dllexport)        int LocalVarDecl; // expected-error{{'LocalVarDecl' must have external linkage when declared 'dllexport'}}
94   __declspec(dllexport)        int LocalVarDef = 1; // expected-error{{'LocalVarDef' must have external linkage when declared 'dllexport'}}
95   __declspec(dllexport) extern int ExternLocalVarDecl;
96   __declspec(dllexport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllexport'}}
97 }
98 
99 
100 
101 //===----------------------------------------------------------------------===//
102 // Variable templates
103 //===----------------------------------------------------------------------===//
104 #if __has_feature(cxx_variable_templates)
105 
106 // Export declaration.
107 template<typename T> __declspec(dllexport) extern int ExternVarTmplDecl;
108 
109 // dllexport implies a definition.
110 template<typename T> __declspec(dllexport) int VarTmplDef;
111 
112 // Export definition.
113 template<typename T> __declspec(dllexport) int VarTmplInit1 = 1;
114 template<typename T> int __declspec(dllexport) VarTmplInit2 = 1;
115 
116 // Declare, then export definition.
117 template<typename T> __declspec(dllexport) extern int VarTmplDeclInit;
118 template<typename T>                              int VarTmplDeclInit = 1;
119 
120 // Redeclarations
121 template<typename T> __declspec(dllexport) extern int VarTmplRedecl1;
122 template<typename T> __declspec(dllexport)        int VarTmplRedecl1 = 1;
123 
124 template<typename T> __declspec(dllexport) extern int VarTmplRedecl2;
125 template<typename T>                              int VarTmplRedecl2 = 1;
126 
127 template<typename T>                       extern int VarTmplRedecl3; // expected-note{{previous declaration is here}}
128 template<typename T> __declspec(dllexport) extern int VarTmplRedecl3; // expected-error{{redeclaration of 'VarTmplRedecl3' cannot add 'dllexport' attribute}}
129 
130 // External linkage is required.
131 template<typename T> __declspec(dllexport) static int StaticVarTmpl; // expected-error{{'StaticVarTmpl' must have external linkage when declared 'dllexport'}}
132 template<typename T> __declspec(dllexport) Internal InternalTypeVarTmpl; // expected-error{{'InternalTypeVarTmpl' must have external linkage when declared 'dllexport'}}
133 #ifndef MS
134 namespace    { template<typename T> __declspec(dllexport) int InternalVarTmpl; } // expected-error{{'(anonymous namespace)::InternalVarTmpl' must have external linkage when declared 'dllexport'}}
135 #endif
136 namespace ns { template<typename T> __declspec(dllexport) int ExternalVarTmpl = 1; }
137 
138 template<typename T> __declspec(dllexport) auto InternalAutoTypeVarTmpl = Internal(); // expected-error{{'InternalAutoTypeVarTmpl' must have external linkage when declared 'dllexport'}}
139 template<typename T> __declspec(dllexport) auto ExternalAutoTypeVarTmpl = External();
140 template External ExternalAutoTypeVarTmpl<ExplicitInst_Exported>;
141 
142 
143 template<typename T> int VarTmpl = 1;
144 template<typename T> __declspec(dllexport) int ExportedVarTmpl = 1;
145 
146 // Export implicit instantiation of an exported variable template.
useVarTmpl()147 int useVarTmpl() { return ExportedVarTmpl<ImplicitInst_Exported>; }
148 
149 // Export explicit instantiation declaration of an exported variable template.
150 extern template int ExportedVarTmpl<ExplicitDecl_Exported>;
151        template int ExportedVarTmpl<ExplicitDecl_Exported>;
152 
153 // Export explicit instantiation definition of an exported variable template.
154 template __declspec(dllexport) int ExportedVarTmpl<ExplicitInst_Exported>;
155 
156 // Export specialization of an exported variable template.
157 template<> __declspec(dllexport) int ExportedVarTmpl<ExplicitSpec_Exported>;
158 template<> __declspec(dllexport) int ExportedVarTmpl<ExplicitSpec_Def_Exported> = 1;
159 
160 // Not exporting specialization of an exported variable template without
161 // explicit dllexport.
162 template<> int ExportedVarTmpl<ExplicitSpec_NotExported>;
163 
164 
165 // Export explicit instantiation declaration of a non-exported variable template.
166 extern template __declspec(dllexport) int VarTmpl<ExplicitDecl_Exported>;
167        template __declspec(dllexport) int VarTmpl<ExplicitDecl_Exported>;
168 
169 // Export explicit instantiation definition of a non-exported variable template.
170 template __declspec(dllexport) int VarTmpl<ExplicitInst_Exported>;
171 
172 // Export specialization of a non-exported variable template.
173 template<> __declspec(dllexport) int VarTmpl<ExplicitSpec_Exported>;
174 template<> __declspec(dllexport) int VarTmpl<ExplicitSpec_Def_Exported> = 1;
175 
176 #endif // __has_feature(cxx_variable_templates)
177 
178 
179 
180 //===----------------------------------------------------------------------===//
181 // Functions
182 //===----------------------------------------------------------------------===//
183 
184 // Export function declaration. Check different placements.
185 __attribute__((dllexport)) void decl1A(); // Correctness check with __attribute__
186 __declspec(dllexport)      void decl1B();
187 
188 void __attribute__((dllexport)) decl2A();
189 void __declspec(dllexport)      decl2B();
190 
191 // Export function definition.
def()192 __declspec(dllexport) void def() {}
193 
194 // extern "C"
externC()195 extern "C" __declspec(dllexport) void externC() {}
196 
197 // Export inline function.
inlineFunc1()198 __declspec(dllexport) inline void inlineFunc1() {}
inlineFunc2()199 inline void __attribute__((dllexport)) inlineFunc2() {}
200 
201 __declspec(dllexport) inline void inlineDecl();
inlineDecl()202                              void inlineDecl() {}
203 
204 __declspec(dllexport) void inlineDef();
inlineDef()205                inline void inlineDef() {}
206 
207 // Redeclarations
208 __declspec(dllexport) void redecl1();
redecl1()209 __declspec(dllexport) void redecl1() {}
210 
211 __declspec(dllexport) void redecl2();
redecl2()212                       void redecl2() {}
213 
214                       void redecl3(); // expected-note{{previous declaration is here}}
215 __declspec(dllexport) void redecl3(); // expected-warning{{redeclaration of 'redecl3' should not add 'dllexport' attribute}}
216 
217 extern "C" {
218                       void redecl4(); // expected-note{{previous declaration is here}}
219 __declspec(dllexport) void redecl4(); // expected-warning{{redeclaration of 'redecl4' should not add 'dllexport' attribute}}
220 }
221 
222                       void redecl5(); // expected-note{{previous declaration is here}}
redecl5()223 __declspec(dllexport) inline void redecl5() {} // expected-warning{{redeclaration of 'redecl5' should not add 'dllexport' attribute}}
224 
225 // Friend functions
226 struct FuncFriend {
227   friend __declspec(dllexport) void friend1();
228   friend __declspec(dllexport) void friend2();
229   friend                       void friend3(); // expected-note{{previous declaration is here}}
230   friend                       void friend4(); // expected-note{{previous declaration is here}}
231 };
friend1()232 __declspec(dllexport) void friend1() {}
friend2()233                       void friend2() {}
friend3()234 __declspec(dllexport) void friend3() {} // expected-warning{{redeclaration of 'friend3' should not add 'dllexport' attribute}}
friend4()235 __declspec(dllexport) inline void friend4() {} // expected-warning{{redeclaration of 'friend4' should not add 'dllexport' attribute}}
236 
237 // Implicit declarations can be redeclared with dllexport.
238 __declspec(dllexport) void* operator new(__SIZE_TYPE__ n);
239 
240 // External linkage is required.
241 __declspec(dllexport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllexport'}}
242 __declspec(dllexport) Internal internalRetFunc(); // expected-error{{'internalRetFunc' must have external linkage when declared 'dllexport'}}
internalFunc()243 namespace    { __declspec(dllexport) void internalFunc() {} } // expected-error{{'(anonymous namespace)::internalFunc' must have external linkage when declared 'dllexport'}}
externalFunc()244 namespace ns { __declspec(dllexport) void externalFunc() {} }
245 
246 // Export deleted function.
247 __declspec(dllexport) void deletedFunc() = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
248 __declspec(dllexport) inline void deletedInlineFunc() = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
249 
250 
251 
252 //===----------------------------------------------------------------------===//
253 // Function templates
254 //===----------------------------------------------------------------------===//
255 
256 // Export function template declaration. Check different placements.
257 template<typename T> __declspec(dllexport) void funcTmplDecl1();
258 template<typename T> void __declspec(dllexport) funcTmplDecl2();
259 
260 // Export function template definition.
funcTmplDef()261 template<typename T> __declspec(dllexport) void funcTmplDef() {}
262 
263 // Export inline function template.
inlineFuncTmpl1()264 template<typename T> __declspec(dllexport) inline void inlineFuncTmpl1() {}
inlineFuncTmpl2()265 template<typename T> inline void __attribute__((dllexport)) inlineFuncTmpl2() {}
266 
267 template<typename T> __declspec(dllexport) inline void inlineFuncTmplDecl();
inlineFuncTmplDecl()268 template<typename T>                              void inlineFuncTmplDecl() {}
269 
270 template<typename T> __declspec(dllexport) void inlineFuncTmplDef();
inlineFuncTmplDef()271 template<typename T>                inline void inlineFuncTmplDef() {}
272 
273 // Redeclarations
274 template<typename T> __declspec(dllexport) void funcTmplRedecl1();
funcTmplRedecl1()275 template<typename T> __declspec(dllexport) void funcTmplRedecl1() {}
276 
277 template<typename T> __declspec(dllexport) void funcTmplRedecl2();
funcTmplRedecl2()278 template<typename T>                       void funcTmplRedecl2() {}
279 
280 template<typename T>                       void funcTmplRedecl3(); // expected-note{{previous declaration is here}}
281 template<typename T> __declspec(dllexport) void funcTmplRedecl3(); // expected-error{{redeclaration of 'funcTmplRedecl3' cannot add 'dllexport' attribute}}
282 
283 template<typename T>                       void funcTmplRedecl4(); // expected-note{{previous declaration is here}}
funcTmplRedecl4()284 template<typename T> __declspec(dllexport) inline void funcTmplRedecl4() {} // expected-error{{redeclaration of 'funcTmplRedecl4' cannot add 'dllexport' attribute}}
285 
286 // Function template friends
287 struct FuncTmplFriend {
288   template<typename T> friend __declspec(dllexport) void funcTmplFriend1();
289   template<typename T> friend __declspec(dllexport) void funcTmplFriend2();
290   template<typename T> friend                       void funcTmplFriend3(); // expected-note{{previous declaration is here}}
291   template<typename T> friend                       void funcTmplFriend4(); // expected-note{{previous declaration is here}}
292 };
funcTmplFriend1()293 template<typename T> __declspec(dllexport) void funcTmplFriend1() {}
funcTmplFriend2()294 template<typename T>                       void funcTmplFriend2() {}
funcTmplFriend3()295 template<typename T> __declspec(dllexport) void funcTmplFriend3() {} // expected-error{{redeclaration of 'funcTmplFriend3' cannot add 'dllexport' attribute}}
funcTmplFriend4()296 template<typename T> __declspec(dllexport) inline void funcTmplFriend4() {} // expected-error{{redeclaration of 'funcTmplFriend4' cannot add 'dllexport' attribute}}
297 
298 // External linkage is required.
299 template<typename T> __declspec(dllexport) static int staticFuncTmpl(); // expected-error{{'staticFuncTmpl' must have external linkage when declared 'dllexport'}}
300 template<typename T> __declspec(dllexport) Internal internalRetFuncTmpl(); // expected-error{{'internalRetFuncTmpl' must have external linkage when declared 'dllexport'}}
301 namespace    { template<typename T> __declspec(dllexport) void internalFuncTmpl(); } // expected-error{{'(anonymous namespace)::internalFuncTmpl' must have external linkage when declared 'dllexport'}}
302 namespace ns { template<typename T> __declspec(dllexport) void externalFuncTmpl(); }
303 
304 
funcTmpl()305 template<typename T> void funcTmpl() {}
306 template<typename T> __declspec(dllexport) void exportedFuncTmplDecl();
exportedFuncTmpl()307 template<typename T> __declspec(dllexport) void exportedFuncTmpl() {}
308 
309 // Export implicit instantiation of an exported function template.
useFunTmplDecl()310 void useFunTmplDecl() { exportedFuncTmplDecl<ImplicitInst_Exported>(); }
useFunTmplDef()311 void useFunTmplDef() { exportedFuncTmpl<ImplicitInst_Exported>(); }
312 
313 // Export explicit instantiation declaration of an exported function template.
314 extern template void exportedFuncTmpl<ExplicitDecl_Exported>();
315        template void exportedFuncTmpl<ExplicitDecl_Exported>();
316 
317 // Export explicit instantiation definition of an exported function template.
318 template void exportedFuncTmpl<ExplicitInst_Exported>();
319 
320 // Export specialization of an exported function template.
321 template<> __declspec(dllexport) void exportedFuncTmpl<ExplicitSpec_Exported>();
exportedFuncTmpl()322 template<> __declspec(dllexport) void exportedFuncTmpl<ExplicitSpec_Def_Exported>() {}
exportedFuncTmpl()323 template<> __declspec(dllexport) inline void exportedFuncTmpl<ExplicitSpec_InlineDef_Exported>() {}
324 
325 // Not exporting specialization of an exported function template without
326 // explicit dllexport.
exportedFuncTmpl()327 template<> void exportedFuncTmpl<ExplicitSpec_NotExported>() {}
328 
329 
330 // Export explicit instantiation declaration of a non-exported function template.
331 extern template __declspec(dllexport) void funcTmpl<ExplicitDecl_Exported>();
332        template __declspec(dllexport) void funcTmpl<ExplicitDecl_Exported>();
333 
334 // Export explicit instantiation definition of a non-exported function template.
335 template __declspec(dllexport) void funcTmpl<ExplicitInst_Exported>();
336 
337 // Export specialization of a non-exported function template.
338 template<> __declspec(dllexport) void funcTmpl<ExplicitSpec_Exported>();
funcTmpl()339 template<> __declspec(dllexport) void funcTmpl<ExplicitSpec_Def_Exported>() {}
funcTmpl()340 template<> __declspec(dllexport) inline void funcTmpl<ExplicitSpec_InlineDef_Exported>() {}
341 
342 
343 
344 //===----------------------------------------------------------------------===//
345 // Classes
346 //===----------------------------------------------------------------------===//
347 
348 namespace {
349   struct __declspec(dllexport) AnonymousClass {}; // expected-error{{(anonymous namespace)::AnonymousClass' must have external linkage when declared 'dllexport'}}
350 }
351 
352 class __declspec(dllexport) ClassDecl;
353 
354 class __declspec(dllexport) ClassDef {};
355 
356 #if defined(MS) || defined (WI)
357 // expected-warning@+3{{'dllexport' attribute ignored}}
358 #endif
359 template <typename T> struct PartiallySpecializedClassTemplate {};
fPartiallySpecializedClassTemplate360 template <typename T> struct __declspec(dllexport) PartiallySpecializedClassTemplate<T*> { void f() {} };
361 
362 template <typename T> struct ExpliciallySpecializedClassTemplate {};
fExpliciallySpecializedClassTemplate363 template <> struct __declspec(dllexport) ExpliciallySpecializedClassTemplate<int> { void f() {} };
364 
365 // Don't instantiate class members of implicitly instantiated templates, even if they are exported.
366 struct IncompleteType;
367 template <typename T> struct __declspec(dllexport) ImplicitlyInstantiatedExportedTemplate {
fImplicitlyInstantiatedExportedTemplate368   int f() { return sizeof(T); } // no-error
369 };
370 ImplicitlyInstantiatedExportedTemplate<IncompleteType> implicitlyInstantiatedExportedTemplate;
371 
372 // Don't instantiate class members of templates with explicit instantiation declarations, even if they are exported.
373 struct IncompleteType2;
374 #if defined(MS) || defined (WI)
375 // expected-note@+2{{attribute is here}}
376 #endif
377 template <typename T> struct __declspec(dllexport) ExportedTemplateWithExplicitInstantiationDecl {
fExportedTemplateWithExplicitInstantiationDecl378   int f() { return sizeof(T); } // no-error
379 };
380 #if defined(MS) || defined (WI)
381 // expected-warning@+2{{explicit instantiation declaration should not be 'dllexport'}}
382 #endif
383 extern template struct ExportedTemplateWithExplicitInstantiationDecl<IncompleteType2>;
384 
385 // Instantiate class members for explicitly instantiated exported templates.
386 struct IncompleteType3; // expected-note{{forward declaration of 'IncompleteType3'}}
387 template <typename T> struct __declspec(dllexport) ExplicitlyInstantiatedExportedTemplate {
fExplicitlyInstantiatedExportedTemplate388   int f() { return sizeof(T); } // expected-error{{invalid application of 'sizeof' to an incomplete type 'IncompleteType3'}}
389 };
390 template struct ExplicitlyInstantiatedExportedTemplate<IncompleteType3>; // expected-note{{in instantiation of member function 'ExplicitlyInstantiatedExportedTemplate<IncompleteType3>::f' requested here}}
391 
392 // In MS mode, instantiate members of class templates that are base classes of exported classes.
393 #ifdef MS
394   // expected-note@+3{{forward declaration of 'IncompleteType4'}}
395   // expected-note@+3{{in instantiation of member function 'BaseClassTemplateOfExportedClass<IncompleteType4>::f' requested here}}
396 #endif
397 struct IncompleteType4;
398 template <typename T> struct BaseClassTemplateOfExportedClass {
399 #ifdef MS
400   // expected-error@+2{{invalid application of 'sizeof' to an incomplete type 'IncompleteType4'}}
401 #endif
fBaseClassTemplateOfExportedClass402   int f() { return sizeof(T); };
403 };
404 struct __declspec(dllexport) ExportedBaseClass : public BaseClassTemplateOfExportedClass<IncompleteType4> {};
405 
406 // Don't instantiate members of explicitly exported class templates that are base classes of exported classes.
407 struct IncompleteType5;
408 template <typename T> struct __declspec(dllexport) ExportedBaseClassTemplateOfExportedClass {
fExportedBaseClassTemplateOfExportedClass409   int f() { return sizeof(T); }; // no-error
410 };
411 struct __declspec(dllexport) ExportedBaseClass2 : public ExportedBaseClassTemplateOfExportedClass<IncompleteType5> {};
412 
413 // Warn about explicit instantiation declarations of dllexport classes.
414 template <typename T> struct ExplicitInstantiationDeclTemplate {};
415 #if defined(MS) || defined (WI)
416 // expected-warning@+2{{explicit instantiation declaration should not be 'dllexport'}} expected-note@+2{{attribute is here}}
417 #endif
418 extern template struct __declspec(dllexport) ExplicitInstantiationDeclTemplate<int>;
419 
420 template <typename T> struct __declspec(dllexport) ExplicitInstantiationDeclExportedTemplate {};
421 #if defined(MS) || defined (WI)
422 // expected-note@-2{{attribute is here}}
423 // expected-warning@+2{{explicit instantiation declaration should not be 'dllexport'}}
424 #endif
425 extern template struct ExplicitInstantiationDeclExportedTemplate<int>;
426 
427 namespace { struct InternalLinkageType {}; }
428 struct __declspec(dllexport) PR23308 {
429   void f(InternalLinkageType*);
430 };
f(InternalLinkageType *)431 void PR23308::f(InternalLinkageType*) {} // No error; we don't try to export f because it has internal linkage.
432 
433 //===----------------------------------------------------------------------===//
434 // Classes with template base classes
435 //===----------------------------------------------------------------------===//
436 
437 template <typename T> class ClassTemplate {};
438 template <typename T> class __declspec(dllexport) ExportedClassTemplate {};
439 template <typename T> class __declspec(dllimport) ImportedClassTemplate {};
440 
funcExplicitlySpecializedTemplate441 template <typename T> struct ExplicitlySpecializedTemplate { void func() {} };
442 #ifdef MS
443 // expected-note@+2{{class template 'ExplicitlySpecializedTemplate<int>' was explicitly specialized here}}
444 #endif
funcExplicitlySpecializedTemplate445 template <> struct ExplicitlySpecializedTemplate<int> { void func() {} };
funcExplicitlyExportSpecializedTemplate446 template <typename T> struct ExplicitlyExportSpecializedTemplate { void func() {} };
funcExplicitlyExportSpecializedTemplate447 template <> struct __declspec(dllexport) ExplicitlyExportSpecializedTemplate<int> { void func() {} };
funcExplicitlyImportSpecializedTemplate448 template <typename T> struct ExplicitlyImportSpecializedTemplate { void func() {} };
funcExplicitlyImportSpecializedTemplate449 template <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate<int> { void func() {} };
450 
funcExplicitlyInstantiatedTemplate451 template <typename T> struct ExplicitlyInstantiatedTemplate { void func() {} };
452 #ifdef MS
453 // expected-note@+2{{class template 'ExplicitlyInstantiatedTemplate<int>' was instantiated here}}
454 #endif
455 template struct ExplicitlyInstantiatedTemplate<int>;
funcExplicitlyExportInstantiatedTemplate456 template <typename T> struct ExplicitlyExportInstantiatedTemplate { void func() {} };
457 template struct __declspec(dllexport) ExplicitlyExportInstantiatedTemplate<int>;
funcExplicitlyExportDeclaredInstantiatedTemplate458 template <typename T> struct ExplicitlyExportDeclaredInstantiatedTemplate { void func() {} };
459 extern template struct ExplicitlyExportDeclaredInstantiatedTemplate<int>;
460 #if not defined(MS) && not defined (WI)
461 // expected-warning@+2{{'dllexport' attribute ignored on explicit instantiation definition}}
462 #endif
463 template struct __declspec(dllexport) ExplicitlyExportDeclaredInstantiatedTemplate<int>;
funcExplicitlyImportInstantiatedTemplate464 template <typename T> struct ExplicitlyImportInstantiatedTemplate { void func() {} };
465 template struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate<int>;
466 
467 // ClassTemplate<int> gets exported.
468 class __declspec(dllexport) DerivedFromTemplate : public ClassTemplate<int> {};
469 
470 // ClassTemplate<int> is already exported.
471 class __declspec(dllexport) DerivedFromTemplate2 : public ClassTemplate<int> {};
472 
473 // ExportedTemplate is explicitly exported.
474 class __declspec(dllexport) DerivedFromExportedTemplate : public ExportedClassTemplate<int> {};
475 
476 // ImportedTemplate is explicitly imported.
477 class __declspec(dllexport) DerivedFromImportedTemplate : public ImportedClassTemplate<int> {};
478 
479 class DerivedFromTemplateD : public ClassTemplate<double> {};
480 // Base class previously implicitly instantiated without attribute; it will get propagated.
481 class __declspec(dllexport) DerivedFromTemplateD2 : public ClassTemplate<double> {};
482 
483 // Base class has explicit instantiation declaration; the attribute will get propagated.
484 extern template class ClassTemplate<float>;
485 class __declspec(dllexport) DerivedFromTemplateF : public ClassTemplate<float> {};
486 
487 class __declspec(dllexport) DerivedFromTemplateB : public ClassTemplate<bool> {};
488 // The second derived class doesn't change anything, the attribute that was propagated first wins.
489 class __declspec(dllimport) DerivedFromTemplateB2 : public ClassTemplate<bool> {};
490 
491 #ifdef MS
492 // expected-warning@+3{{propagating dll attribute to explicitly specialized base class template without dll attribute is not supported}}
493 // expected-note@+2{{attribute is here}}
494 #endif
495 struct __declspec(dllexport) DerivedFromExplicitlySpecializedTemplate : public ExplicitlySpecializedTemplate<int> {};
496 
497 // Base class alredy specialized with export attribute.
498 struct __declspec(dllexport) DerivedFromExplicitlyExportSpecializedTemplate : public ExplicitlyExportSpecializedTemplate<int> {};
499 
500 // Base class already specialized with import attribute.
501 struct __declspec(dllexport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate<int> {};
502 
503 #ifdef MS
504 // expected-warning@+3{{propagating dll attribute to already instantiated base class template without dll attribute is not supported}}
505 // expected-note@+2{{attribute is here}}
506 #endif
507 struct __declspec(dllexport) DerivedFromExplicitlyInstantiatedTemplate : public ExplicitlyInstantiatedTemplate<int> {};
508 
509 // Base class already instantiated with export attribute.
510 struct __declspec(dllexport) DerivedFromExplicitlyExportInstantiatedTemplate : public ExplicitlyExportInstantiatedTemplate<int> {};
511 
512 // Base class already instantiated with import attribute.
513 struct __declspec(dllexport) DerivedFromExplicitlyImportInstantiatedTemplate : public ExplicitlyImportInstantiatedTemplate<int> {};
514 
funcExplicitInstantiationDeclTemplateBase515 template <typename T> struct ExplicitInstantiationDeclTemplateBase { void func() {} };
516 extern template struct ExplicitInstantiationDeclTemplateBase<int>;
517 struct __declspec(dllexport) DerivedFromExplicitInstantiationDeclTemplateBase : public ExplicitInstantiationDeclTemplateBase<int> {};
518 
519 
520 //===----------------------------------------------------------------------===//
521 // Precedence
522 //===----------------------------------------------------------------------===//
523 
524 // dllexport takes precedence over dllimport if both are specified.
525 __attribute__((dllimport, dllexport))       extern int PrecedenceExternGlobal1A; // expected-warning{{'dllimport' attribute ignored}}
526 __declspec(dllimport) __declspec(dllexport) extern int PrecedenceExternGlobal1B; // expected-warning{{'dllimport' attribute ignored}}
527 
528 __attribute__((dllexport, dllimport))       extern int PrecedenceExternGlobal2A; // expected-warning{{'dllimport' attribute ignored}}
529 __declspec(dllexport) __declspec(dllimport) extern int PrecedenceExternGlobal2B; // expected-warning{{'dllimport' attribute ignored}}
530 
531 __attribute__((dllimport, dllexport))       int PrecedenceGlobal1A; // expected-warning{{'dllimport' attribute ignored}}
532 __declspec(dllimport) __declspec(dllexport) int PrecedenceGlobal1B; // expected-warning{{'dllimport' attribute ignored}}
533 
534 __attribute__((dllexport, dllimport))       int PrecedenceGlobal2A; // expected-warning{{'dllimport' attribute ignored}}
535 __declspec(dllexport) __declspec(dllimport) int PrecedenceGlobal2B; // expected-warning{{'dllimport' attribute ignored}}
536 
537 __declspec(dllexport) extern int PrecedenceExternGlobalRedecl1;
538 __declspec(dllimport) extern int PrecedenceExternGlobalRedecl1; // expected-warning{{'dllimport' attribute ignored}}
539 
540 __declspec(dllimport) extern int PrecedenceExternGlobalRedecl2; // expected-warning{{'dllimport' attribute ignored}}
541 __declspec(dllexport) extern int PrecedenceExternGlobalRedecl2;
542 
543 __declspec(dllexport) extern int PrecedenceGlobalRedecl1;
544 __declspec(dllimport)        int PrecedenceGlobalRedecl1; // expected-warning{{'dllimport' attribute ignored}}
545 
546 __declspec(dllimport) extern int PrecedenceGlobalRedecl2; // expected-warning{{'dllimport' attribute ignored}}
547 __declspec(dllexport)        int PrecedenceGlobalRedecl2;
548 
precedence1A()549 void __attribute__((dllimport, dllexport))       precedence1A() {} // expected-warning{{'dllimport' attribute ignored}}
precedence1B()550 void __declspec(dllimport) __declspec(dllexport) precedence1B() {} // expected-warning{{'dllimport' attribute ignored}}
551 
precedence2A()552 void __attribute__((dllexport, dllimport))       precedence2A() {} // expected-warning{{'dllimport' attribute ignored}}
precedence2B()553 void __declspec(dllexport) __declspec(dllimport) precedence2B() {} // expected-warning{{'dllimport' attribute ignored}}
554 
555 void __declspec(dllimport) precedenceRedecl1(); // expected-warning{{'dllimport' attribute ignored}}
precedenceRedecl1()556 void __declspec(dllexport) precedenceRedecl1() {}
557 
558 void __declspec(dllexport) precedenceRedecl2();
precedenceRedecl2()559 void __declspec(dllimport) precedenceRedecl2() {} // expected-warning{{'dllimport' attribute ignored}}
560 
561 
562 
563 //===----------------------------------------------------------------------===//
564 // Class members
565 //===----------------------------------------------------------------------===//
566 
567 // Export individual members of a class.
568 struct ExportMembers {
569   struct Nested {
570     __declspec(dllexport) void normalDef();
571   };
572 
573   __declspec(dllexport)                void normalDecl();
574   __declspec(dllexport)                void normalDef();
normalInclassExportMembers575   __declspec(dllexport)                void normalInclass() {}
576   __declspec(dllexport)                void normalInlineDef();
577   __declspec(dllexport)         inline void normalInlineDecl();
578   __declspec(dllexport) virtual        void virtualDecl();
579   __declspec(dllexport) virtual        void virtualDef();
virtualInclassExportMembers580   __declspec(dllexport) virtual        void virtualInclass() {}
581   __declspec(dllexport) virtual        void virtualInlineDef();
582   __declspec(dllexport) virtual inline void virtualInlineDecl();
583   __declspec(dllexport) static         void staticDecl();
584   __declspec(dllexport) static         void staticDef();
staticInclassExportMembers585   __declspec(dllexport) static         void staticInclass() {}
586   __declspec(dllexport) static         void staticInlineDef();
587   __declspec(dllexport) static  inline void staticInlineDecl();
588 
589 protected:
590   __declspec(dllexport)                void protectedDef();
591 private:
592   __declspec(dllexport)                void privateDef();
593 public:
594 
595   __declspec(dllexport)                int  Field; // expected-warning{{'dllexport' attribute only applies to}}
596   __declspec(dllexport) static         int  StaticField;
597   __declspec(dllexport) static         int  StaticFieldDef;
598   __declspec(dllexport) static  const  int  StaticConstField;
599   __declspec(dllexport) static  const  int  StaticConstFieldDef;
600   __declspec(dllexport) static  const  int  StaticConstFieldEqualInit = 1;
601   __declspec(dllexport) static  const  int  StaticConstFieldBraceInit{1};
602   __declspec(dllexport) constexpr static int ConstexprField = 1;
603   __declspec(dllexport) constexpr static int ConstexprFieldDef = 1;
604 };
605 
normalDef()606        void ExportMembers::Nested::normalDef() {}
normalDef()607        void ExportMembers::normalDef() {}
normalInlineDef()608 inline void ExportMembers::normalInlineDef() {}
normalInlineDecl()609        void ExportMembers::normalInlineDecl() {}
virtualDef()610        void ExportMembers::virtualDef() {}
virtualInlineDef()611 inline void ExportMembers::virtualInlineDef() {}
virtualInlineDecl()612        void ExportMembers::virtualInlineDecl() {}
staticDef()613        void ExportMembers::staticDef() {}
staticInlineDef()614 inline void ExportMembers::staticInlineDef() {}
staticInlineDecl()615        void ExportMembers::staticInlineDecl() {}
protectedDef()616        void ExportMembers::protectedDef() {}
privateDef()617        void ExportMembers::privateDef() {}
618 
619        int  ExportMembers::StaticFieldDef;
620 const  int  ExportMembers::StaticConstFieldDef = 1;
621 constexpr int ExportMembers::ConstexprFieldDef;
622 
623 
624 // Export on member definitions.
625 struct ExportMemberDefs {
626   __declspec(dllexport)                void normalDef();
627   __declspec(dllexport)                void normalInlineDef();
628   __declspec(dllexport)         inline void normalInlineDecl();
629   __declspec(dllexport) virtual        void virtualDef();
630   __declspec(dllexport) virtual        void virtualInlineDef();
631   __declspec(dllexport) virtual inline void virtualInlineDecl();
632   __declspec(dllexport) static         void staticDef();
633   __declspec(dllexport) static         void staticInlineDef();
634   __declspec(dllexport) static  inline void staticInlineDecl();
635 
636   __declspec(dllexport) static         int  StaticField;
637   __declspec(dllexport) static  const  int  StaticConstField;
638   __declspec(dllexport) constexpr static int ConstexprField = 1;
639 };
640 
normalDef()641 __declspec(dllexport)        void ExportMemberDefs::normalDef() {}
normalInlineDef()642 __declspec(dllexport) inline void ExportMemberDefs::normalInlineDef() {}
normalInlineDecl()643 __declspec(dllexport)        void ExportMemberDefs::normalInlineDecl() {}
virtualDef()644 __declspec(dllexport)        void ExportMemberDefs::virtualDef() {}
virtualInlineDef()645 __declspec(dllexport) inline void ExportMemberDefs::virtualInlineDef() {}
virtualInlineDecl()646 __declspec(dllexport)        void ExportMemberDefs::virtualInlineDecl() {}
staticDef()647 __declspec(dllexport)        void ExportMemberDefs::staticDef() {}
staticInlineDef()648 __declspec(dllexport) inline void ExportMemberDefs::staticInlineDef() {}
staticInlineDecl()649 __declspec(dllexport)        void ExportMemberDefs::staticInlineDecl() {}
650 
651 __declspec(dllexport)        int  ExportMemberDefs::StaticField;
652 __declspec(dllexport) const  int  ExportMemberDefs::StaticConstField = 1;
653 __declspec(dllexport) constexpr int ExportMemberDefs::ConstexprField;
654 
655 
656 // Export special member functions.
657 struct ExportSpecials {
ExportSpecialsExportSpecials658   __declspec(dllexport) ExportSpecials() {}
659   __declspec(dllexport) ~ExportSpecials();
660   __declspec(dllexport) inline ExportSpecials(const ExportSpecials&);
661   __declspec(dllexport) ExportSpecials& operator=(const ExportSpecials&);
662   __declspec(dllexport) ExportSpecials(ExportSpecials&&);
663   __declspec(dllexport) ExportSpecials& operator=(ExportSpecials&&);
664 };
665 
~ExportSpecials()666 ExportSpecials::~ExportSpecials() {}
ExportSpecials(const ExportSpecials &)667 ExportSpecials::ExportSpecials(const ExportSpecials&) {}
operator =(const ExportSpecials &)668 inline ExportSpecials& ExportSpecials::operator=(const ExportSpecials&) { return *this; }
ExportSpecials(ExportSpecials &&)669 ExportSpecials::ExportSpecials(ExportSpecials&&) {}
operator =(ExportSpecials &&)670 ExportSpecials& ExportSpecials::operator=(ExportSpecials&&) { return *this; }
671 
672 
673 // Export allocation functions.
674 extern "C" void* malloc(__SIZE_TYPE__ size);
675 extern "C" void free(void* p);
676 struct ExportAlloc {
677   __declspec(dllexport) void* operator new(__SIZE_TYPE__);
678   __declspec(dllexport) void* operator new[](__SIZE_TYPE__);
679   __declspec(dllexport) void operator delete(void*);
680   __declspec(dllexport) void operator delete[](void*);
681 };
operator new(__SIZE_TYPE__ n)682 void* ExportAlloc::operator new(__SIZE_TYPE__ n) { return malloc(n); }
operator new[](__SIZE_TYPE__ n)683 void* ExportAlloc::operator new[](__SIZE_TYPE__ n) { return malloc(n); }
operator delete(void * p)684 void ExportAlloc::operator delete(void* p) { free(p); }
operator delete[](void * p)685 void ExportAlloc::operator delete[](void* p) { free(p); }
686 
687 
688 // Export deleted member functions.
689 struct ExportDeleted {
690   __declspec(dllexport) ExportDeleted() = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
691   __declspec(dllexport) ~ExportDeleted() = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
692   __declspec(dllexport) ExportDeleted(const ExportDeleted&) = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
693   __declspec(dllexport) ExportDeleted& operator=(const ExportDeleted&) = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
694   __declspec(dllexport) ExportDeleted(ExportDeleted&&) = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
695   __declspec(dllexport) ExportDeleted& operator=(ExportDeleted&&) = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
696   __declspec(dllexport) void deleted() = delete; // expected-error{{attribute 'dllexport' cannot be applied to a deleted function}}
697 };
698 
699 
700 // Export defaulted member functions.
701 struct ExportDefaulted {
702   __declspec(dllexport) ExportDefaulted() = default;
703   __declspec(dllexport) ~ExportDefaulted() = default;
704   __declspec(dllexport) ExportDefaulted(const ExportDefaulted&) = default;
705   __declspec(dllexport) ExportDefaulted& operator=(const ExportDefaulted&) = default;
706   __declspec(dllexport) ExportDefaulted(ExportDefaulted&&) = default;
707   __declspec(dllexport) ExportDefaulted& operator=(ExportDefaulted&&) = default;
708 };
709 
710 
711 // Export defaulted member function definitions.
712 struct ExportDefaultedDefs {
713   __declspec(dllexport) ExportDefaultedDefs();
714   __declspec(dllexport) ~ExportDefaultedDefs();
715 
716   __declspec(dllexport) inline ExportDefaultedDefs(const ExportDefaultedDefs&);
717   __declspec(dllexport) ExportDefaultedDefs& operator=(const ExportDefaultedDefs&);
718 
719   __declspec(dllexport) ExportDefaultedDefs(ExportDefaultedDefs&&);
720   __declspec(dllexport) ExportDefaultedDefs& operator=(ExportDefaultedDefs&&);
721 };
722 
723 // Export definitions.
724 __declspec(dllexport) ExportDefaultedDefs::ExportDefaultedDefs() = default;
725 ExportDefaultedDefs::~ExportDefaultedDefs() = default;
726 
727 // Export inline declaration and definition.
728 __declspec(dllexport) ExportDefaultedDefs::ExportDefaultedDefs(const ExportDefaultedDefs&) = default;
729 inline ExportDefaultedDefs& ExportDefaultedDefs::operator=(const ExportDefaultedDefs&) = default;
730 
731 __declspec(dllexport) ExportDefaultedDefs::ExportDefaultedDefs(ExportDefaultedDefs&&) = default;
732 ExportDefaultedDefs& ExportDefaultedDefs::operator=(ExportDefaultedDefs&&) = default;
733 
734 
735 // Redeclarations cannot add dllexport.
736 struct MemberRedecl {
737                  void normalDef();         // expected-note{{previous declaration is here}}
738                  void normalInlineDef();   // expected-note{{previous declaration is here}}
739           inline void normalInlineDecl();  // expected-note{{previous declaration is here}}
740   virtual        void virtualDef();        // expected-note{{previous declaration is here}}
741   virtual        void virtualInlineDef();  // expected-note{{previous declaration is here}}
742   virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}}
743   static         void staticDef();         // expected-note{{previous declaration is here}}
744   static         void staticInlineDef();   // expected-note{{previous declaration is here}}
745   static  inline void staticInlineDecl();  // expected-note{{previous declaration is here}}
746 
747   static         int  StaticField;         // expected-note{{previous declaration is here}}
748   static  const  int  StaticConstField;    // expected-note{{previous declaration is here}}
749   constexpr static int ConstexprField = 1; // expected-note-re{{previous {{(declaration|definition)}} is here}}
750 };
751 
normalDef()752 __declspec(dllexport)        void MemberRedecl::normalDef() {}         // expected-error{{redeclaration of 'MemberRedecl::normalDef' cannot add 'dllexport' attribute}}
normalInlineDef()753 __declspec(dllexport) inline void MemberRedecl::normalInlineDef() {}   // expected-error{{redeclaration of 'MemberRedecl::normalInlineDef' cannot add 'dllexport' attribute}}
normalInlineDecl()754 __declspec(dllexport)        void MemberRedecl::normalInlineDecl() {}  // expected-error{{redeclaration of 'MemberRedecl::normalInlineDecl' cannot add 'dllexport' attribute}}
virtualDef()755 __declspec(dllexport)        void MemberRedecl::virtualDef() {}        // expected-error{{redeclaration of 'MemberRedecl::virtualDef' cannot add 'dllexport' attribute}}
virtualInlineDef()756 __declspec(dllexport) inline void MemberRedecl::virtualInlineDef() {}  // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDef' cannot add 'dllexport' attribute}}
virtualInlineDecl()757 __declspec(dllexport)        void MemberRedecl::virtualInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDecl' cannot add 'dllexport' attribute}}
staticDef()758 __declspec(dllexport)        void MemberRedecl::staticDef() {}         // expected-error{{redeclaration of 'MemberRedecl::staticDef' cannot add 'dllexport' attribute}}
staticInlineDef()759 __declspec(dllexport) inline void MemberRedecl::staticInlineDef() {}   // expected-error{{redeclaration of 'MemberRedecl::staticInlineDef' cannot add 'dllexport' attribute}}
staticInlineDecl()760 __declspec(dllexport)        void MemberRedecl::staticInlineDecl() {}  // expected-error{{redeclaration of 'MemberRedecl::staticInlineDecl' cannot add 'dllexport' attribute}}
761 
762 __declspec(dllexport)        int  MemberRedecl::StaticField = 1;       // expected-error{{redeclaration of 'MemberRedecl::StaticField' cannot add 'dllexport' attribute}}
763 __declspec(dllexport) const  int  MemberRedecl::StaticConstField = 1;  // expected-error{{redeclaration of 'MemberRedecl::StaticConstField' cannot add 'dllexport' attribute}}
764 #ifdef MS
765 // expected-warning@+4{{attribute declaration must precede definition}}
766 #else
767 // expected-error@+2{{redeclaration of 'MemberRedecl::ConstexprField' cannot add 'dllexport' attribute}}
768 #endif
769 __declspec(dllexport) constexpr int MemberRedecl::ConstexprField;
770 
771 #ifdef MS
772 struct __declspec(dllexport) ClassWithMultipleDefaultCtors {
ClassWithMultipleDefaultCtorsClassWithMultipleDefaultCtors773   ClassWithMultipleDefaultCtors(int = 40) {} // expected-error{{'__declspec(dllexport)' cannot be applied to more than one default constructor}}
ClassWithMultipleDefaultCtorsClassWithMultipleDefaultCtors774   ClassWithMultipleDefaultCtors(int = 30, ...) {} // expected-note{{declared here}}
775 };
776 template <typename T>
777 struct ClassTemplateWithMultipleDefaultCtors {
ClassTemplateWithMultipleDefaultCtorsClassTemplateWithMultipleDefaultCtors778   __declspec(dllexport) ClassTemplateWithMultipleDefaultCtors(int = 40) {}      // expected-error{{'__declspec(dllexport)' cannot be applied to more than one default constructor}}
ClassTemplateWithMultipleDefaultCtorsClassTemplateWithMultipleDefaultCtors779   __declspec(dllexport) ClassTemplateWithMultipleDefaultCtors(int = 30, ...) {} // expected-note{{declared here}}
780 };
781 
782 template <typename T> struct HasDefaults {
HasDefaultsHasDefaults783   HasDefaults(int x = sizeof(T)) {} // expected-error {{invalid application of 'sizeof'}}
784 };
785 template struct __declspec(dllexport) HasDefaults<char>;
786 
787 template struct
788 __declspec(dllexport) // expected-note {{in instantiation of default function argument expression for 'HasDefaults<void>' required here}}
789 HasDefaults<void>; // expected-note {{in instantiation of member function 'HasDefaults<void>::HasDefaults' requested here}}
790 
791 template <typename T> struct HasDefaults2 {
792   __declspec(dllexport) // expected-note {{in instantiation of default function argument expression for 'HasDefaults2<void>' required here}}
HasDefaults2HasDefaults2793   HasDefaults2(int x = sizeof(T)) {} // expected-error {{invalid application of 'sizeof'}}
794 };
795 template struct HasDefaults2<void>; // expected-note {{in instantiation of member function 'HasDefaults2<void>::HasDefaults2' requested here}}
796 
797 template <typename T> struct __declspec(dllexport) HasDefaults3 { // expected-note{{in instantiation of default function argument expression for 'HasDefaults3<void>' required here}}
HasDefaults3HasDefaults3798   HasDefaults3(int x = sizeof(T)) {} // expected-error {{invalid application of 'sizeof'}}
799 };
HasDefaults3(int)800 template <> HasDefaults3<void>::HasDefaults3(int) {};
801 
802 #endif
803 
804 //===----------------------------------------------------------------------===//
805 // Class member templates
806 //===----------------------------------------------------------------------===//
807 
808 struct ExportMemberTmpl {
809   template<typename T> __declspec(dllexport)               void normalDecl();
810   template<typename T> __declspec(dllexport)               void normalDef();
normalInclassExportMemberTmpl811   template<typename T> __declspec(dllexport)               void normalInclass() {}
812   template<typename T> __declspec(dllexport)               void normalInlineDef();
813   template<typename T> __declspec(dllexport)        inline void normalInlineDecl();
814   template<typename T> __declspec(dllexport) static        void staticDecl();
815   template<typename T> __declspec(dllexport) static        void staticDef();
staticInclassExportMemberTmpl816   template<typename T> __declspec(dllexport) static        void staticInclass() {}
817   template<typename T> __declspec(dllexport) static        void staticInlineDef();
818   template<typename T> __declspec(dllexport) static inline void staticInlineDecl();
819 
820 #if __has_feature(cxx_variable_templates)
821   template<typename T> __declspec(dllexport) static        int  StaticField;
822   template<typename T> __declspec(dllexport) static        int  StaticFieldDef;
823   template<typename T> __declspec(dllexport) static const  int  StaticConstField;
824   template<typename T> __declspec(dllexport) static const  int  StaticConstFieldDef;
825   template<typename T> __declspec(dllexport) static const  int  StaticConstFieldEqualInit = 1;
826   template<typename T> __declspec(dllexport) static const  int  StaticConstFieldBraceInit{1};
827   template<typename T> __declspec(dllexport) constexpr static int ConstexprField = 1;
828   template<typename T> __declspec(dllexport) constexpr static int ConstexprFieldDef = 1;
829 #endif // __has_feature(cxx_variable_templates)
830 };
831 
normalDef()832 template<typename T>        void ExportMemberTmpl::normalDef() {}
normalInlineDef()833 template<typename T> inline void ExportMemberTmpl::normalInlineDef() {}
normalInlineDecl()834 template<typename T>        void ExportMemberTmpl::normalInlineDecl() {}
staticDef()835 template<typename T>        void ExportMemberTmpl::staticDef() {}
staticInlineDef()836 template<typename T> inline void ExportMemberTmpl::staticInlineDef() {}
staticInlineDecl()837 template<typename T>        void ExportMemberTmpl::staticInlineDecl() {}
838 
839 #if __has_feature(cxx_variable_templates)
840 template<typename T>        int  ExportMemberTmpl::StaticFieldDef;
841 template<typename T> const  int  ExportMemberTmpl::StaticConstFieldDef = 1;
842 template<typename T> constexpr int ExportMemberTmpl::ConstexprFieldDef;
843 #endif // __has_feature(cxx_variable_templates)
844 
845 
846 // Redeclarations cannot add dllexport.
847 struct MemTmplRedecl {
848   template<typename T>               void normalDef();         // expected-note{{previous declaration is here}}
849   template<typename T>               void normalInlineDef();   // expected-note{{previous declaration is here}}
850   template<typename T>        inline void normalInlineDecl();  // expected-note{{previous declaration is here}}
851   template<typename T> static        void staticDef();         // expected-note{{previous declaration is here}}
852   template<typename T> static        void staticInlineDef();   // expected-note{{previous declaration is here}}
853   template<typename T> static inline void staticInlineDecl();  // expected-note{{previous declaration is here}}
854 
855 #if __has_feature(cxx_variable_templates)
856   template<typename T> static        int  StaticField;         // expected-note{{previous declaration is here}}
857   template<typename T> static const  int  StaticConstField;    // expected-note{{previous declaration is here}}
858   template<typename T> constexpr static int ConstexprField = 1; // expected-note-re{{previous {{(declaration|definition)}} is here}}
859 #endif // __has_feature(cxx_variable_templates)
860 };
861 
normalDef()862 template<typename T> __declspec(dllexport)        void MemTmplRedecl::normalDef() {}        // expected-error{{redeclaration of 'MemTmplRedecl::normalDef' cannot add 'dllexport' attribute}}
normalInlineDef()863 template<typename T> __declspec(dllexport) inline void MemTmplRedecl::normalInlineDef() {}  // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDef' cannot add 'dllexport' attribute}}
normalInlineDecl()864 template<typename T> __declspec(dllexport)        void MemTmplRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDecl' cannot add 'dllexport' attribute}}
staticDef()865 template<typename T> __declspec(dllexport)        void MemTmplRedecl::staticDef() {}        // expected-error{{redeclaration of 'MemTmplRedecl::staticDef' cannot add 'dllexport' attribute}}
staticInlineDef()866 template<typename T> __declspec(dllexport) inline void MemTmplRedecl::staticInlineDef() {}  // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDef' cannot add 'dllexport' attribute}}
staticInlineDecl()867 template<typename T> __declspec(dllexport)        void MemTmplRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDecl' cannot add 'dllexport' attribute}}
868 
869 #if __has_feature(cxx_variable_templates)
870 template<typename T> __declspec(dllexport)        int  MemTmplRedecl::StaticField = 1;      // expected-error{{redeclaration of 'MemTmplRedecl::StaticField' cannot add 'dllexport' attribute}}
871 template<typename T> __declspec(dllexport) const  int  MemTmplRedecl::StaticConstField = 1; // expected-error{{redeclaration of 'MemTmplRedecl::StaticConstField' cannot add 'dllexport' attribute}}
872 
873 #ifdef MS
874 // expected-warning@+4{{attribute declaration must precede definition}}
875 #else
876 // expected-error@+2{{redeclaration of 'MemTmplRedecl::ConstexprField' cannot add 'dllexport' attribute}}
877 #endif
878 template<typename T> __declspec(dllexport) constexpr int MemTmplRedecl::ConstexprField;
879 #endif // __has_feature(cxx_variable_templates)
880 
881 
882 
883 struct MemFunTmpl {
normalDefMemFunTmpl884   template<typename T>                              void normalDef() {}
exportedNormalMemFunTmpl885   template<typename T> __declspec(dllexport)        void exportedNormal() {}
staticDefMemFunTmpl886   template<typename T>                       static void staticDef() {}
exportedStaticMemFunTmpl887   template<typename T> __declspec(dllexport) static void exportedStatic() {}
888 };
889 
890 // Export implicit instantiation of an exported member function template.
useMemFunTmpl()891 void useMemFunTmpl() {
892   MemFunTmpl().exportedNormal<ImplicitInst_Exported>();
893   MemFunTmpl().exportedStatic<ImplicitInst_Exported>();
894 }
895 
896 // Export explicit instantiation declaration of an exported member function
897 // template.
898 extern template void MemFunTmpl::exportedNormal<ExplicitDecl_Exported>();
899        template void MemFunTmpl::exportedNormal<ExplicitDecl_Exported>();
900 
901 extern template void MemFunTmpl::exportedStatic<ExplicitDecl_Exported>();
902        template void MemFunTmpl::exportedStatic<ExplicitDecl_Exported>();
903 
904 // Export explicit instantiation definition of an exported member function
905 // template.
906 template void MemFunTmpl::exportedNormal<ExplicitInst_Exported>();
907 template void MemFunTmpl::exportedStatic<ExplicitInst_Exported>();
908 
909 // Export specialization of an exported member function template.
910 template<> __declspec(dllexport) void MemFunTmpl::exportedNormal<ExplicitSpec_Exported>();
exportedNormal()911 template<> __declspec(dllexport) void MemFunTmpl::exportedNormal<ExplicitSpec_Def_Exported>() {}
exportedNormal()912 template<> __declspec(dllexport) inline void MemFunTmpl::exportedNormal<ExplicitSpec_InlineDef_Exported>() {}
913 
914 template<> __declspec(dllexport) void MemFunTmpl::exportedStatic<ExplicitSpec_Exported>();
exportedStatic()915 template<> __declspec(dllexport) void MemFunTmpl::exportedStatic<ExplicitSpec_Def_Exported>() {}
exportedStatic()916 template<> __declspec(dllexport) inline void MemFunTmpl::exportedStatic<ExplicitSpec_InlineDef_Exported>() {}
917 
918 // Not exporting specialization of an exported member function template without
919 // explicit dllexport.
exportedNormal()920 template<> void MemFunTmpl::exportedNormal<ExplicitSpec_NotExported>() {}
exportedStatic()921 template<> void MemFunTmpl::exportedStatic<ExplicitSpec_NotExported>() {}
922 
923 
924 // Export explicit instantiation declaration of a non-exported member function
925 // template.
926 extern template __declspec(dllexport) void MemFunTmpl::normalDef<ExplicitDecl_Exported>();
927        template __declspec(dllexport) void MemFunTmpl::normalDef<ExplicitDecl_Exported>();
928 
929 extern template __declspec(dllexport) void MemFunTmpl::staticDef<ExplicitDecl_Exported>();
930        template __declspec(dllexport) void MemFunTmpl::staticDef<ExplicitDecl_Exported>();
931 
932 // Export explicit instantiation definition of a non-exported member function
933 // template.
934 template __declspec(dllexport) void MemFunTmpl::normalDef<ExplicitInst_Exported>();
935 template __declspec(dllexport) void MemFunTmpl::staticDef<ExplicitInst_Exported>();
936 
937 // Export specialization of a non-exported member function template.
938 template<> __declspec(dllexport) void MemFunTmpl::normalDef<ExplicitSpec_Exported>();
normalDef()939 template<> __declspec(dllexport) void MemFunTmpl::normalDef<ExplicitSpec_Def_Exported>() {}
normalDef()940 template<> __declspec(dllexport) inline void MemFunTmpl::normalDef<ExplicitSpec_InlineDef_Exported>() {}
941 
942 template<> __declspec(dllexport) void MemFunTmpl::staticDef<ExplicitSpec_Exported>();
staticDef()943 template<> __declspec(dllexport) void MemFunTmpl::staticDef<ExplicitSpec_Def_Exported>() {}
staticDef()944 template<> __declspec(dllexport) inline void MemFunTmpl::staticDef<ExplicitSpec_InlineDef_Exported>() {}
945 
946 
947 
948 #if __has_feature(cxx_variable_templates)
949 struct MemVarTmpl {
950   template<typename T>                       static const int StaticVar = 1;
951   template<typename T> __declspec(dllexport) static const int ExportedStaticVar = 1;
952 };
953 template<typename T> const int MemVarTmpl::StaticVar;
954 template<typename T> const int MemVarTmpl::ExportedStaticVar;
955 
956 // Export implicit instantiation of an exported member variable template.
useMemVarTmpl()957 int useMemVarTmpl() { return MemVarTmpl::ExportedStaticVar<ImplicitInst_Exported>; }
958 
959 // Export explicit instantiation declaration of an exported member variable
960 // template.
961 extern template const int MemVarTmpl::ExportedStaticVar<ExplicitDecl_Exported>;
962        template const int MemVarTmpl::ExportedStaticVar<ExplicitDecl_Exported>;
963 
964 // Export explicit instantiation definition of an exported member variable
965 // template.
966 template const int MemVarTmpl::ExportedStaticVar<ExplicitInst_Exported>;
967 
968 // Export specialization of an exported member variable template.
969 template<> __declspec(dllexport) const int MemVarTmpl::ExportedStaticVar<ExplicitSpec_Exported>;
970 template<> __declspec(dllexport) const int MemVarTmpl::ExportedStaticVar<ExplicitSpec_Def_Exported> = 1;
971 
972 // Not exporting specialization of an exported member variable template without
973 // explicit dllexport.
974 template<> const int MemVarTmpl::ExportedStaticVar<ExplicitSpec_NotExported>;
975 
976 
977 // Export explicit instantiation declaration of a non-exported member variable
978 // template.
979 extern template __declspec(dllexport) const int MemVarTmpl::StaticVar<ExplicitDecl_Exported>;
980        template __declspec(dllexport) const int MemVarTmpl::StaticVar<ExplicitDecl_Exported>;
981 
982 // Export explicit instantiation definition of a non-exported member variable
983 // template.
984 template __declspec(dllexport) const int MemVarTmpl::StaticVar<ExplicitInst_Exported>;
985 
986 // Export specialization of a non-exported member variable template.
987 template<> __declspec(dllexport) const int MemVarTmpl::StaticVar<ExplicitSpec_Exported>;
988 template<> __declspec(dllexport) const int MemVarTmpl::StaticVar<ExplicitSpec_Def_Exported> = 1;
989 
990 #endif // __has_feature(cxx_variable_templates)
991 
992 
993 
994 //===----------------------------------------------------------------------===//
995 // Class template members
996 //===----------------------------------------------------------------------===//
997 
998 // Export individual members of a class template.
999 template<typename T>
1000 struct ExportClassTmplMembers {
1001   __declspec(dllexport)                void normalDecl();
1002   __declspec(dllexport)                void normalDef();
normalInclassExportClassTmplMembers1003   __declspec(dllexport)                void normalInclass() {}
1004   __declspec(dllexport)                void normalInlineDef();
1005   __declspec(dllexport)         inline void normalInlineDecl();
1006   __declspec(dllexport) virtual        void virtualDecl();
1007   __declspec(dllexport) virtual        void virtualDef();
virtualInclassExportClassTmplMembers1008   __declspec(dllexport) virtual        void virtualInclass() {}
1009   __declspec(dllexport) virtual        void virtualInlineDef();
1010   __declspec(dllexport) virtual inline void virtualInlineDecl();
1011   __declspec(dllexport) static         void staticDecl();
1012   __declspec(dllexport) static         void staticDef();
staticInclassExportClassTmplMembers1013   __declspec(dllexport) static         void staticInclass() {}
1014   __declspec(dllexport) static         void staticInlineDef();
1015   __declspec(dllexport) static  inline void staticInlineDecl();
1016 
1017 protected:
1018   __declspec(dllexport)                void protectedDef();
1019 private:
1020   __declspec(dllexport)                void privateDef();
1021 public:
1022 
1023   __declspec(dllexport)                int  Field; // expected-warning{{'dllexport' attribute only applies to}}
1024   __declspec(dllexport) static         int  StaticField;
1025   __declspec(dllexport) static         int  StaticFieldDef;
1026   __declspec(dllexport) static  const  int  StaticConstField;
1027   __declspec(dllexport) static  const  int  StaticConstFieldDef;
1028   __declspec(dllexport) static  const  int  StaticConstFieldEqualInit = 1;
1029   __declspec(dllexport) static  const  int  StaticConstFieldBraceInit{1};
1030   __declspec(dllexport) constexpr static int ConstexprField = 1;
1031   __declspec(dllexport) constexpr static int ConstexprFieldDef = 1;
1032 };
1033 
normalDef()1034 template<typename T>        void ExportClassTmplMembers<T>::normalDef() {}
normalInlineDef()1035 template<typename T> inline void ExportClassTmplMembers<T>::normalInlineDef() {}
normalInlineDecl()1036 template<typename T>        void ExportClassTmplMembers<T>::normalInlineDecl() {}
virtualDef()1037 template<typename T>        void ExportClassTmplMembers<T>::virtualDef() {}
virtualInlineDef()1038 template<typename T> inline void ExportClassTmplMembers<T>::virtualInlineDef() {}
virtualInlineDecl()1039 template<typename T>        void ExportClassTmplMembers<T>::virtualInlineDecl() {}
staticDef()1040 template<typename T>        void ExportClassTmplMembers<T>::staticDef() {}
staticInlineDef()1041 template<typename T> inline void ExportClassTmplMembers<T>::staticInlineDef() {}
staticInlineDecl()1042 template<typename T>        void ExportClassTmplMembers<T>::staticInlineDecl() {}
protectedDef()1043 template<typename T>        void ExportClassTmplMembers<T>::protectedDef() {}
privateDef()1044 template<typename T>        void ExportClassTmplMembers<T>::privateDef() {}
1045 
1046 template<typename T>        int  ExportClassTmplMembers<T>::StaticFieldDef;
1047 template<typename T> const  int  ExportClassTmplMembers<T>::StaticConstFieldDef = 1;
1048 template<typename T> constexpr int ExportClassTmplMembers<T>::ConstexprFieldDef;
1049 
1050 template struct ExportClassTmplMembers<ImplicitInst_Exported>;
1051 
1052 
1053 // Redeclarations cannot add dllexport.
1054 template<typename T>
1055 struct CTMR /*ClassTmplMemberRedecl*/ {
1056                  void normalDef();         // expected-note{{previous declaration is here}}
1057                  void normalInlineDef();   // expected-note{{previous declaration is here}}
1058           inline void normalInlineDecl();  // expected-note{{previous declaration is here}}
1059   virtual        void virtualDef();        // expected-note{{previous declaration is here}}
1060   virtual        void virtualInlineDef();  // expected-note{{previous declaration is here}}
1061   virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}}
1062   static         void staticDef();         // expected-note{{previous declaration is here}}
1063   static         void staticInlineDef();   // expected-note{{previous declaration is here}}
1064   static  inline void staticInlineDecl();  // expected-note{{previous declaration is here}}
1065 
1066   static         int  StaticField;         // expected-note{{previous declaration is here}}
1067   static  const  int  StaticConstField;    // expected-note{{previous declaration is here}}
1068   constexpr static int ConstexprField = 1; // expected-note-re{{previous {{(definition|declaration)}} is here}}
1069 };
1070 
normalDef()1071 template<typename T> __declspec(dllexport)        void CTMR<T>::normalDef() {}         // expected-error{{redeclaration of 'CTMR::normalDef' cannot add 'dllexport' attribute}}
normalInlineDef()1072 template<typename T> __declspec(dllexport) inline void CTMR<T>::normalInlineDef() {}   // expected-error{{redeclaration of 'CTMR::normalInlineDef' cannot add 'dllexport' attribute}}
normalInlineDecl()1073 template<typename T> __declspec(dllexport)        void CTMR<T>::normalInlineDecl() {}  // expected-error{{redeclaration of 'CTMR::normalInlineDecl' cannot add 'dllexport' attribute}}
virtualDef()1074 template<typename T> __declspec(dllexport)        void CTMR<T>::virtualDef() {}        // expected-error{{redeclaration of 'CTMR::virtualDef' cannot add 'dllexport' attribute}}
virtualInlineDef()1075 template<typename T> __declspec(dllexport) inline void CTMR<T>::virtualInlineDef() {}  // expected-error{{redeclaration of 'CTMR::virtualInlineDef' cannot add 'dllexport' attribute}}
virtualInlineDecl()1076 template<typename T> __declspec(dllexport)        void CTMR<T>::virtualInlineDecl() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDecl' cannot add 'dllexport' attribute}}
staticDef()1077 template<typename T> __declspec(dllexport)        void CTMR<T>::staticDef() {}         // expected-error{{redeclaration of 'CTMR::staticDef' cannot add 'dllexport' attribute}}
staticInlineDef()1078 template<typename T> __declspec(dllexport) inline void CTMR<T>::staticInlineDef() {}   // expected-error{{redeclaration of 'CTMR::staticInlineDef' cannot add 'dllexport' attribute}}
staticInlineDecl()1079 template<typename T> __declspec(dllexport)        void CTMR<T>::staticInlineDecl() {}  // expected-error{{redeclaration of 'CTMR::staticInlineDecl' cannot add 'dllexport' attribute}}
1080 
1081 template<typename T> __declspec(dllexport)        int  CTMR<T>::StaticField = 1;       // expected-error{{redeclaration of 'CTMR::StaticField' cannot add 'dllexport' attribute}}
1082 template<typename T> __declspec(dllexport) const  int  CTMR<T>::StaticConstField = 1;  // expected-error{{redeclaration of 'CTMR::StaticConstField' cannot add 'dllexport' attribute}}
1083 #ifdef MS
1084 // expected-warning@+4{{attribute declaration must precede definition}}
1085 #else
1086 // expected-error@+2{{redeclaration of 'CTMR::ConstexprField' cannot add 'dllexport' attribute}}
1087 #endif
1088 template<typename T> __declspec(dllexport) constexpr int CTMR<T>::ConstexprField;
1089 
1090 
1091 
1092 //===----------------------------------------------------------------------===//
1093 // Class template member templates
1094 //===----------------------------------------------------------------------===//
1095 
1096 template<typename T>
1097 struct ExportClsTmplMemTmpl {
1098   template<typename U> __declspec(dllexport)               void normalDecl();
1099   template<typename U> __declspec(dllexport)               void normalDef();
normalInclassExportClsTmplMemTmpl1100   template<typename U> __declspec(dllexport)               void normalInclass() {}
1101   template<typename U> __declspec(dllexport)               void normalInlineDef();
1102   template<typename U> __declspec(dllexport)        inline void normalInlineDecl();
1103   template<typename U> __declspec(dllexport) static        void staticDecl();
1104   template<typename U> __declspec(dllexport) static        void staticDef();
staticInclassExportClsTmplMemTmpl1105   template<typename U> __declspec(dllexport) static        void staticInclass() {}
1106   template<typename U> __declspec(dllexport) static        void staticInlineDef();
1107   template<typename U> __declspec(dllexport) static inline void staticInlineDecl();
1108 
1109 #if __has_feature(cxx_variable_templates)
1110   template<typename U> __declspec(dllexport) static        int  StaticField;
1111   template<typename U> __declspec(dllexport) static        int  StaticFieldDef;
1112   template<typename U> __declspec(dllexport) static const  int  StaticConstField;
1113   template<typename U> __declspec(dllexport) static const  int  StaticConstFieldDef;
1114   template<typename U> __declspec(dllexport) static const  int  StaticConstFieldEqualInit = 1;
1115   template<typename U> __declspec(dllexport) static const  int  StaticConstFieldBraceInit{1};
1116   template<typename U> __declspec(dllexport) constexpr static int ConstexprField = 1;
1117   template<typename U> __declspec(dllexport) constexpr static int ConstexprFieldDef = 1;
1118 #endif // __has_feature(cxx_variable_templates)
1119 };
1120 
normalDef()1121 template<typename T> template<typename U>        void ExportClsTmplMemTmpl<T>::normalDef() {}
normalInlineDef()1122 template<typename T> template<typename U> inline void ExportClsTmplMemTmpl<T>::normalInlineDef() {}
normalInlineDecl()1123 template<typename T> template<typename U>        void ExportClsTmplMemTmpl<T>::normalInlineDecl() {}
staticDef()1124 template<typename T> template<typename U>        void ExportClsTmplMemTmpl<T>::staticDef() {}
staticInlineDef()1125 template<typename T> template<typename U> inline void ExportClsTmplMemTmpl<T>::staticInlineDef() {}
staticInlineDecl()1126 template<typename T> template<typename U>        void ExportClsTmplMemTmpl<T>::staticInlineDecl() {}
1127 
1128 #if __has_feature(cxx_variable_templates)
1129 template<typename T> template<typename U>        int  ExportClsTmplMemTmpl<T>::StaticFieldDef;
1130 template<typename T> template<typename U> const  int  ExportClsTmplMemTmpl<T>::StaticConstFieldDef = 1;
1131 template<typename T> template<typename U> constexpr int ExportClsTmplMemTmpl<T>::ConstexprFieldDef;
1132 #endif // __has_feature(cxx_variable_templates)
1133 
1134 
1135 // Redeclarations cannot add dllexport.
1136 template<typename T>
1137 struct CTMTR /*ClassTmplMemberTmplRedecl*/ {
1138   template<typename U>               void normalDef();         // expected-note{{previous declaration is here}}
1139   template<typename U>               void normalInlineDef();   // expected-note{{previous declaration is here}}
1140   template<typename U>        inline void normalInlineDecl();  // expected-note{{previous declaration is here}}
1141   template<typename U> static        void staticDef();         // expected-note{{previous declaration is here}}
1142   template<typename U> static        void staticInlineDef();   // expected-note{{previous declaration is here}}
1143   template<typename U> static inline void staticInlineDecl();  // expected-note{{previous declaration is here}}
1144 
1145 #if __has_feature(cxx_variable_templates)
1146   template<typename U> static        int  StaticField;         // expected-note{{previous declaration is here}}
1147   template<typename U> static const  int  StaticConstField;    // expected-note{{previous declaration is here}}
1148   template<typename U> constexpr static int ConstexprField = 1; // expected-note-re{{previous {{(declaration|definition)}} is here}}
1149 #endif // __has_feature(cxx_variable_templates)
1150 };
1151 
normalDef()1152 template<typename T> template<typename U> __declspec(dllexport)        void CTMTR<T>::normalDef() {}         // expected-error{{redeclaration of 'CTMTR::normalDef' cannot add 'dllexport' attribute}}
normalInlineDef()1153 template<typename T> template<typename U> __declspec(dllexport) inline void CTMTR<T>::normalInlineDef() {}   // expected-error{{redeclaration of 'CTMTR::normalInlineDef' cannot add 'dllexport' attribute}}
normalInlineDecl()1154 template<typename T> template<typename U> __declspec(dllexport)        void CTMTR<T>::normalInlineDecl() {}  // expected-error{{redeclaration of 'CTMTR::normalInlineDecl' cannot add 'dllexport' attribute}}
staticDef()1155 template<typename T> template<typename U> __declspec(dllexport)        void CTMTR<T>::staticDef() {}         // expected-error{{redeclaration of 'CTMTR::staticDef' cannot add 'dllexport' attribute}}
staticInlineDef()1156 template<typename T> template<typename U> __declspec(dllexport) inline void CTMTR<T>::staticInlineDef() {}   // expected-error{{redeclaration of 'CTMTR::staticInlineDef' cannot add 'dllexport' attribute}}
staticInlineDecl()1157 template<typename T> template<typename U> __declspec(dllexport)        void CTMTR<T>::staticInlineDecl() {}  // expected-error{{redeclaration of 'CTMTR::staticInlineDecl' cannot add 'dllexport' attribute}}
1158 
1159 #if __has_feature(cxx_variable_templates)
1160 template<typename T> template<typename U> __declspec(dllexport)        int  CTMTR<T>::StaticField = 1;       // expected-error{{redeclaration of 'CTMTR::StaticField' cannot add 'dllexport' attribute}}
1161 template<typename T> template<typename U> __declspec(dllexport) const  int  CTMTR<T>::StaticConstField = 1;  // expected-error{{redeclaration of 'CTMTR::StaticConstField' cannot add 'dllexport' attribute}}
1162 #ifdef MS
1163 // expected-warning@+4{{attribute declaration must precede definition}}
1164 #else
1165 // expected-error@+2{{redeclaration of 'CTMTR::ConstexprField' cannot add 'dllexport' attribute}}
1166 #endif
1167 template<typename T> template<typename U> __declspec(dllexport) constexpr int CTMTR<T>::ConstexprField;
1168 #endif // __has_feature(cxx_variable_templates)
1169 
1170 // FIXME: Precedence rules seem to be different for classes.
1171 
1172 //===----------------------------------------------------------------------===//
1173 // Lambdas
1174 //===----------------------------------------------------------------------===//
1175 // The MS ABI doesn't provide a stable mangling for lambdas, so they can't be imported or exported.
1176 #if defined(MS) || defined (WI)
1177 // expected-error@+2{{lambda cannot be declared 'dllexport'}}
1178 #endif
__anon5afd2c590802() 1179 auto Lambda = []() __declspec(dllexport) -> bool { return true; };
1180