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 -DGNU %s
4 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DGNU %s
5 // RUN: %clang_cc1 -triple x86_64-mingw32 -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
6 // RUN: %clang_cc1 -triple i686-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
7 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
8 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -fdeclspec -verify -std=c++11 -Wunsupported-dll-base-class-template -DPS %s
9 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -fdeclspec -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
10 // RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
12 // Helper structs to make templates more expressive.
13 struct ImplicitInst_Imported
{};
14 struct ExplicitDecl_Imported
{};
15 struct ExplicitInst_Imported
{};
16 struct ExplicitSpec_Imported
{};
17 struct ExplicitSpec_Def_Imported
{};
18 struct ExplicitSpec_InlineDef_Imported
{};
19 struct ExplicitSpec_NotImported
{};
20 namespace { struct Internal
{}; }
24 __declspec(dllimport
) typedef int typedef1
;
25 // expected-warning@-1{{'dllimport' attribute only applies to functions, variables, classes, and Objective-C interfaces}}
26 typedef __declspec(dllimport
) int typedef2
;
27 // expected-warning@-1{{'dllimport' attribute only applies to}}
28 typedef int __declspec(dllimport
) typedef3
;
29 // expected-warning@-1{{'dllimport' attribute only applies to}}
30 typedef __declspec(dllimport
) void (*FunTy
)();
31 // expected-warning@-1{{'dllimport' attribute only applies to}}
32 enum __declspec(dllimport
) Enum
{};
33 // expected-warning@-1{{'dllimport' attribute only applies to}}
34 #if __has_feature(cxx_strong_enums)
35 enum class __declspec(dllimport
) EnumClass
{};
36 // expected-warning@-1{{'dllimport' attribute only applies to}}
41 //===----------------------------------------------------------------------===//
43 //===----------------------------------------------------------------------===//
45 // Import declaration.
46 __declspec(dllimport
) extern int ExternGlobalDecl
;
48 // dllimport implies a declaration.
49 __declspec(dllimport
) int GlobalDecl
;
50 int **__attribute__((dllimport
))* GlobalDeclChunkAttr
;
51 int GlobalDeclAttr
__attribute__((dllimport
));
53 // Not allowed on definitions.
54 __declspec(dllimport
) extern int ExternGlobalInit
= 1; // expected-error{{definition of dllimport data}}
55 __declspec(dllimport
) int GlobalInit1
= 1; // expected-error{{definition of dllimport data}}
56 int __declspec(dllimport
) GlobalInit2
= 1; // expected-error{{definition of dllimport data}}
58 // Declare, then reject definition.
60 // expected-note@+2{{previous attribute is here}}
62 __declspec(dllimport
) extern int ExternGlobalDeclInit
; // expected-note{{previous declaration is here}}
63 #if defined(MS) || defined(WI) || defined(PS)
64 // expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
66 // expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
68 int ExternGlobalDeclInit
= 1;
71 // expected-note@+2{{previous attribute is here}}
73 __declspec(dllimport
) int GlobalDeclInit
; // expected-note{{previous declaration is here}}
74 #if defined(MS) || defined(WI) || defined(PS)
75 // expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
77 // expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
79 int GlobalDeclInit
= 1;
82 // expected-note@+2{{previous attribute is here}}
84 int *__attribute__((dllimport
)) GlobalDeclChunkAttrInit
; // expected-note{{previous declaration is here}}
85 #if defined(MS) || defined(WI) || defined(PS)
86 // expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
88 // expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
90 int *GlobalDeclChunkAttrInit
= 0;
93 // expected-note@+2{{previous attribute is here}}
95 int GlobalDeclAttrInit
__attribute__((dllimport
)); // expected-note{{previous declaration is here}}
96 #if defined(MS) || defined(WI) || defined(PS)
97 // expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
99 // expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
101 int GlobalDeclAttrInit
= 1;
104 __declspec(dllimport
) extern int GlobalRedecl1
;
105 __declspec(dllimport
) extern int GlobalRedecl1
;
107 __declspec(dllimport
) int GlobalRedecl2a
;
108 __declspec(dllimport
) int GlobalRedecl2a
;
110 int *__attribute__((dllimport
)) GlobalRedecl2b
;
111 int *__attribute__((dllimport
)) GlobalRedecl2b
;
113 int GlobalRedecl2c
__attribute__((dllimport
));
114 int GlobalRedecl2c
__attribute__((dllimport
));
116 __declspec(dllimport
) extern int GlobalRedecl3
; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
117 extern int GlobalRedecl3
; // expected-warning{{'GlobalRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
119 extern int GlobalRedecl4
; // expected-note{{previous declaration is here}}
120 __declspec(dllimport
) extern int GlobalRedecl4
; // expected-warning{{redeclaration of 'GlobalRedecl4' should not add 'dllimport' attribute}}
123 extern int GlobalRedecl5
; // expected-note{{previous declaration is here}}
124 __declspec(dllimport
) extern int GlobalRedecl5
; // expected-warning{{redeclaration of 'GlobalRedecl5' should not add 'dllimport' attribute}}
127 // External linkage is required.
128 __declspec(dllimport
) static int StaticGlobal
; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllimport'}}
129 __declspec(dllimport
) Internal InternalTypeGlobal
; // expected-error{{'InternalTypeGlobal' must have external linkage when declared 'dllimport'}}
131 namespace { __declspec(dllimport
) int InternalGlobal
; } // expected-error{{'(anonymous namespace)::InternalGlobal' must have external linkage when declared 'dllimport'}}
133 namespace ns
{ __declspec(dllimport
) int ExternalGlobal
; }
135 __declspec(dllimport
) auto InternalAutoTypeGlobal
= Internal(); // expected-error{{'InternalAutoTypeGlobal' must have external linkage when declared 'dllimport'}}
136 // expected-error@-1{{definition of dllimport data}}
138 // Thread local variables are invalid.
139 __declspec(dllimport
) __thread
int ThreadLocalGlobal
; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllimport'}}
140 // This doesn't work on MinGW, because there, dllimport on the inline function is ignored.
142 inline void __declspec(dllimport
) ImportedInlineWithThreadLocal() {
143 static __thread
int OK
; // no-error
147 // Import in local scope.
148 __declspec(dllimport
) float LocalRedecl1
; // expected-note{{previous declaration is here}}
149 __declspec(dllimport
) float LocalRedecl2
; // expected-note{{previous declaration is here}}
150 __declspec(dllimport
) float LocalRedecl3
; // expected-note{{previous declaration is here}}
151 void functionScope() {
152 __declspec(dllimport
) int LocalRedecl1
; // expected-error{{redeclaration of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
153 int *__attribute__((dllimport
)) LocalRedecl2
; // expected-error{{redeclaration of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
154 int LocalRedecl3
__attribute__((dllimport
)); // expected-error{{redeclaration of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
156 __declspec(dllimport
) int LocalVarDecl
;
157 __declspec(dllimport
) int LocalVarDef
= 1; // expected-error{{definition of dllimport data}}
158 __declspec(dllimport
) extern int ExternLocalVarDecl
;
159 __declspec(dllimport
) extern int ExternLocalVarDef
= 1; // expected-error{{definition of dllimport data}}
160 __declspec(dllimport
) static int StaticLocalVar
; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllimport'}}
165 //===----------------------------------------------------------------------===//
166 // Variable templates
167 //===----------------------------------------------------------------------===//
168 #if __has_feature(cxx_variable_templates)
170 // Import declaration.
171 template<typename T
> __declspec(dllimport
) extern int ExternVarTmplDecl
;
173 // dllimport implies a declaration.
174 template<typename T
> __declspec(dllimport
) int VarTmplDecl
;
176 // Not allowed on definitions.
177 template<typename T
> __declspec(dllimport
) extern int ExternVarTmplInit
= 1; // expected-error{{definition of dllimport data}}
178 template<typename T
> __declspec(dllimport
) int VarTmplInit1
= 1; // expected-error{{definition of dllimport data}}
179 template<typename T
> int __declspec(dllimport
) VarTmplInit2
= 1; // expected-error{{definition of dllimport data}}
181 // Declare, then reject definition.
183 // expected-note@+3{{previous attribute is here}}
185 template <typename T
>
186 __declspec(dllimport
) extern int ExternVarTmplDeclInit
; // expected-note{{previous declaration is here}}
187 #if defined(MS) || defined(WI) || defined(PS)
188 // expected-warning@+5{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
190 // expected-warning@+3{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
192 template <typename T
>
193 int ExternVarTmplDeclInit
= 1;
196 // expected-note@+3{{previous attribute is here}}
198 template <typename T
>
199 __declspec(dllimport
) int VarTmplDeclInit
; // expected-note{{previous declaration is here}}
200 #if defined(MS) || defined(WI) || defined(PS)
201 // expected-warning@+5{{'VarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
203 // expected-warning@+3{{'VarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
205 template <typename T
>
206 int VarTmplDeclInit
= 1;
209 template<typename T
> __declspec(dllimport
) extern int VarTmplRedecl1
;
210 template<typename T
> __declspec(dllimport
) extern int VarTmplRedecl1
;
212 template<typename T
> __declspec(dllimport
) int VarTmplRedecl2
;
213 template<typename T
> __declspec(dllimport
) int VarTmplRedecl2
;
215 template<typename T
> __declspec(dllimport
) extern int VarTmplRedecl3
; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
216 template<typename T
> extern int VarTmplRedecl3
; // expected-warning{{'VarTmplRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
218 template<typename T
> extern int VarTmplRedecl4
; // expected-note{{previous declaration is here}}
219 template<typename T
> __declspec(dllimport
) extern int VarTmplRedecl4
; // expected-error{{redeclaration of 'VarTmplRedecl4' cannot add 'dllimport' attribute}}
221 // External linkage is required.
222 template<typename T
> __declspec(dllimport
) static int StaticVarTmpl
; // expected-error{{'StaticVarTmpl' must have external linkage when declared 'dllimport'}}
223 template<typename T
> __declspec(dllimport
) Internal InternalTypeVarTmpl
; // expected-error{{'InternalTypeVarTmpl' must have external linkage when declared 'dllimport'}}
225 namespace { template<typename T
> __declspec(dllimport
) int InternalVarTmpl
; } // expected-error{{'(anonymous namespace)::InternalVarTmpl' must have external linkage when declared 'dllimport'}}
227 namespace ns
{ template<typename T
> __declspec(dllimport
) int ExternalVarTmpl
; }
229 template<typename T
> __declspec(dllimport
) auto InternalAutoTypeVarTmpl
= Internal(); // expected-error{{definition of dllimport data}} // expected-error{{'InternalAutoTypeVarTmpl' must have external linkage when declared 'dllimport'}}
232 template<typename T
> int VarTmpl
;
233 template<typename T
> __declspec(dllimport
) int ImportedVarTmpl
;
235 // Import implicit instantiation of an imported variable template.
236 int useVarTmpl() { return ImportedVarTmpl
<ImplicitInst_Imported
>; }
238 // Import explicit instantiation declaration of an imported variable template.
239 extern template int ImportedVarTmpl
<ExplicitDecl_Imported
>;
241 // An explicit instantiation definition of an imported variable template cannot
242 // be imported because the template must be defined which is illegal.
244 // Import specialization of an imported variable template.
245 template<> __declspec(dllimport
) int ImportedVarTmpl
<ExplicitSpec_Imported
>;
246 template<> __declspec(dllimport
) int ImportedVarTmpl
<ExplicitSpec_Def_Imported
> = 1; // expected-error{{definition of dllimport data}}
248 // Not importing specialization of an imported variable template without
249 // explicit dllimport.
250 template<> int ImportedVarTmpl
<ExplicitSpec_NotImported
>;
253 // Import explicit instantiation declaration of a non-imported variable template.
254 extern template __declspec(dllimport
) int VarTmpl
<ExplicitDecl_Imported
>;
256 // Import explicit instantiation definition of a non-imported variable template.
257 template __declspec(dllimport
) int VarTmpl
<ExplicitInst_Imported
>;
259 // Import specialization of a non-imported variable template.
260 template<> __declspec(dllimport
) int VarTmpl
<ExplicitSpec_Imported
>;
261 template<> __declspec(dllimport
) int VarTmpl
<ExplicitSpec_Def_Imported
> = 1; // expected-error{{definition of dllimport data}}
263 #endif // __has_feature(cxx_variable_templates)
266 //===----------------------------------------------------------------------===//
268 //===----------------------------------------------------------------------===//
270 // Import function declaration. Check different placements.
271 __attribute__((dllimport
)) void decl1A(); // Validation check with __attribute__
272 __declspec(dllimport
) void decl1B();
274 void __attribute__((dllimport
)) decl2A();
275 void __declspec(dllimport
) decl2B();
277 // Not allowed on function definitions.
278 __declspec(dllimport
) void def() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
281 extern "C" __declspec(dllimport
) void externC();
283 // Import inline function.
285 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
286 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
288 __declspec(dllimport
) inline void inlineFunc1() {}
289 inline void __attribute__((dllimport
)) inlineFunc2() {}
292 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
294 __declspec(dllimport
) inline void inlineDecl();
297 __declspec(dllimport
) void inlineDef();
299 // expected-warning@+2{{'inlineDef' redeclared inline; 'dllimport' attribute ignored}}
301 inline void inlineDef() {}
304 __declspec(dllimport
) void redecl1();
305 __declspec(dllimport
) void redecl1();
307 __declspec(dllimport
) void redecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
308 void redecl2(); // expected-warning{{'redecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
311 // expected-note@+2{{previous attribute is here}}
313 __declspec(dllimport
) void redecl3(); // expected-note{{previous declaration is here}}
314 // NB: Both MSVC and Clang issue a warning and make redecl3 dllexport.
315 #if defined(MS) || defined(WI) || defined(PS)
316 // expected-warning@+4{{'redecl3' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
318 // expected-warning@+2{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
322 void redecl4(); // expected-note{{previous declaration is here}}
323 __declspec(dllimport
) void redecl4(); // expected-warning{{redeclaration of 'redecl4' should not add 'dllimport' attribute}}
326 void redecl5(); // expected-note{{previous declaration is here}}
327 __declspec(dllimport
) void redecl5(); // expected-warning{{redeclaration of 'redecl5' should not add 'dllimport' attribute}}
330 #if defined(MS) || defined(WI) || defined(PS)
331 void redecl6(); // expected-note{{previous declaration is here}}
332 __declspec(dllimport
) inline void redecl6() {} // expected-warning{{redeclaration of 'redecl6' should not add 'dllimport' attribute}}
335 __declspec(dllimport
) inline void redecl6() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
340 friend __declspec(dllimport
) void friend1();
341 friend __declspec(dllimport
) void friend2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
343 // expected-note@+2{{previous attribute is here}}
345 friend __declspec(dllimport
) void friend3(); // expected-note{{previous declaration is here}}
346 friend void friend4(); // expected-note{{previous declaration is here}}
347 #if defined(MS) || defined(WI) || defined(PS)
348 // expected-note@+2{{previous declaration is here}}
350 friend void friend5();
352 __declspec(dllimport
) void friend1();
353 void friend2(); // expected-warning{{'friend2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
354 #if defined(MS) || defined(WI) || defined(PS)
355 // expected-warning@+4{{'friend3' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
357 // expected-warning@+2{{'friend3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
360 __declspec(dllimport
) void friend4(); // expected-warning{{redeclaration of 'friend4' should not add 'dllimport' attribute}}
361 #if defined(MS) || defined(WI) || defined(PS)
362 __declspec(dllimport
) inline void friend5() {} // expected-warning{{redeclaration of 'friend5' should not add 'dllimport' attribute}}
364 __declspec(dllimport
) inline void friend5() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
368 void __declspec(dllimport
) friend6(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
369 void __declspec(dllimport
) friend7();
371 friend void friend6(); // expected-warning{{'friend6' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
372 friend void ::friend7();
375 // Implicit declarations can be redeclared with dllimport.
376 __declspec(dllimport
) void* operator new(__SIZE_TYPE__ n
);
378 // External linkage is required.
379 __declspec(dllimport
) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}
380 __declspec(dllimport
) Internal
internalRetFunc(); // expected-error{{'internalRetFunc' must have external linkage when declared 'dllimport'}}
381 namespace { __declspec(dllimport
) void internalFunc(); } // expected-error{{'(anonymous namespace)::internalFunc' must have external linkage when declared 'dllimport'}}
382 namespace ns
{ __declspec(dllimport
) void externalFunc(); }
384 // Import deleted functions.
385 // FIXME: Deleted functions are definitions so a missing inline is diagnosed
386 // here which is irrelevant. But because the delete keyword is parsed later
387 // there is currently no straight-forward way to avoid this diagnostic.
388 __declspec(dllimport
) void deletedFunc() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}} expected-error{{dllimport cannot be applied to non-inline function definition}}
389 #if defined(MS) || defined(WI) || defined(PS)
390 __declspec(dllimport
) inline void deletedInlineFunc() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
392 __declspec(dllimport
) inline void deletedInlineFunc() = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
397 //===----------------------------------------------------------------------===//
398 // Function templates
399 //===----------------------------------------------------------------------===//
401 // Import function template declaration. Check different placements.
402 template<typename T
> __declspec(dllimport
) void funcTmplDecl1();
403 template<typename T
> void __declspec(dllimport
) funcTmplDecl2();
405 // Import function template definition.
406 template<typename T
> __declspec(dllimport
) void funcTmplDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
408 // Import inline function template.
409 #ifdef GNU // MinGW always ignores dllimport on inline functions.
411 template<typename T
> __declspec(dllimport
) inline void inlineFuncTmpl1() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
412 template<typename T
> inline void __attribute__((dllimport
)) inlineFuncTmpl2() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
414 template<typename T
> __declspec(dllimport
) inline void inlineFuncTmplDecl(); // expected-warning{{'dllimport' attribute ignored on inline function}}
415 template<typename T
> void inlineFuncTmplDecl() {}
417 template<typename T
> __declspec(dllimport
) void inlineFuncTmplDef();
418 template<typename T
> inline void inlineFuncTmplDef() {} // expected-warning{{'inlineFuncTmplDef' redeclared inline; 'dllimport' attribute ignored}}
420 #else // MSVC drops dllimport when the function template is redeclared without it. (It doesn't warn, but we do.)
422 template<typename T
> __declspec(dllimport
) inline void inlineFuncTmpl1() {}
423 template<typename T
> inline void __attribute__((dllimport
)) inlineFuncTmpl2() {}
425 template<typename T
> __declspec(dllimport
) inline void inlineFuncTmplDecl(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
426 template<typename T
> void inlineFuncTmplDecl() {} // expected-warning{{'inlineFuncTmplDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
428 template<typename T
> __declspec(dllimport
) void inlineFuncTmplDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
429 template<typename T
> inline void inlineFuncTmplDef() {} // expected-warning{{'inlineFuncTmplDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
433 template<typename T
> __declspec(dllimport
) void funcTmplRedecl1();
434 template<typename T
> __declspec(dllimport
) void funcTmplRedecl1();
436 template<typename T
> __declspec(dllimport
) void funcTmplRedecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
437 template<typename T
> void funcTmplRedecl2(); // expected-warning{{'funcTmplRedecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
439 template<typename T
> __declspec(dllimport
) void funcTmplRedecl3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
440 template<typename T
> void funcTmplRedecl3() {} // expected-warning{{'funcTmplRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
442 template<typename T
> void funcTmplRedecl4(); // expected-note{{previous declaration is here}}
443 template<typename T
> __declspec(dllimport
) void funcTmplRedecl4(); // expected-error{{redeclaration of 'funcTmplRedecl4' cannot add 'dllimport' attribute}}
446 template<typename T
> void funcTmplRedecl5(); // expected-note{{previous declaration is here}}
447 template<typename T
> __declspec(dllimport
) inline void funcTmplRedecl5() {} // expected-error{{redeclaration of 'funcTmplRedecl5' cannot add 'dllimport' attribute}}
450 // Function template friends
451 struct FuncTmplFriend
{
452 template<typename T
> friend __declspec(dllimport
) void funcTmplFriend1();
453 template<typename T
> friend __declspec(dllimport
) void funcTmplFriend2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
454 template<typename T
> friend __declspec(dllimport
) void funcTmplFriend3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
455 template<typename T
> friend void funcTmplFriend4(); // expected-note{{previous declaration is here}}
457 // expected-warning@+4{{'dllimport' attribute ignored on inline function}}
459 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
461 template<typename T
> friend __declspec(dllimport
) inline void funcTmplFriend5();
463 template<typename T
> __declspec(dllimport
) void funcTmplFriend1();
464 template<typename T
> void funcTmplFriend2(); // expected-warning{{'funcTmplFriend2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
465 template<typename T
> void funcTmplFriend3() {} // expected-warning{{'funcTmplFriend3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
466 template<typename T
> __declspec(dllimport
) void funcTmplFriend4(); // expected-error{{redeclaration of 'funcTmplFriend4' cannot add 'dllimport' attribute}}
467 #if defined(MS) || defined(WI) || defined(PS)
468 // expected-warning@+2{{'funcTmplFriend5' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
470 template<typename T
> inline void funcTmplFriend5() {}
472 // External linkage is required.
473 template<typename T
> __declspec(dllimport
) static int staticFuncTmpl(); // expected-error{{'staticFuncTmpl' must have external linkage when declared 'dllimport'}}
474 template<typename T
> __declspec(dllimport
) Internal
internalRetFuncTmpl(); // expected-error{{'internalRetFuncTmpl' must have external linkage when declared 'dllimport'}}
475 namespace { template<typename T
> __declspec(dllimport
) void internalFuncTmpl(); } // expected-error{{'(anonymous namespace)::internalFuncTmpl' must have external linkage when declared 'dllimport'}}
476 namespace ns
{ template<typename T
> __declspec(dllimport
) void externalFuncTmpl(); }
479 template<typename T
> void funcTmpl() {}
480 template<typename T
> inline void inlineFuncTmpl() {}
481 template<typename T
> __declspec(dllimport
) void importedFuncTmplDecl();
483 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
485 template<typename T
> __declspec(dllimport
) inline void importedFuncTmpl() {}
487 // Import implicit instantiation of an imported function template.
488 void useFunTmplDecl() { importedFuncTmplDecl
<ImplicitInst_Imported
>(); }
489 void useFunTmplDef() { importedFuncTmpl
<ImplicitInst_Imported
>(); }
491 // Import explicit instantiation declaration of an imported function template.
492 extern template void importedFuncTmpl
<ExplicitDecl_Imported
>();
494 // Import explicit instantiation definition of an imported function template.
495 // NB: MSVC fails this instantiation without explicit dllimport which is most
496 // likely a bug because an implicit instantiation is accepted.
497 template void importedFuncTmpl
<ExplicitInst_Imported
>();
499 // Import specialization of an imported function template. A definition must be
501 template<> __declspec(dllimport
) void importedFuncTmpl
<ExplicitSpec_Imported
>();
502 template<> __declspec(dllimport
) void importedFuncTmpl
<ExplicitSpec_Def_Imported
>() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
504 template<> __declspec(dllimport
) inline void importedFuncTmpl
<ExplicitSpec_InlineDef_Imported
>() {}
507 // Not importing specialization of an imported function template without
508 // explicit dllimport.
509 template<> void importedFuncTmpl
<ExplicitSpec_NotImported
>() {}
512 // Import explicit instantiation declaration of a non-imported function template.
513 extern template __declspec(dllimport
) void funcTmpl
<ExplicitDecl_Imported
>();
515 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
517 extern template __declspec(dllimport
) void inlineFuncTmpl
<ExplicitDecl_Imported
>();
519 // Import explicit instantiation definition of a non-imported function template.
520 template __declspec(dllimport
) void funcTmpl
<ExplicitInst_Imported
>();
522 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
524 template __declspec(dllimport
) void inlineFuncTmpl
<ExplicitInst_Imported
>();
526 // Import specialization of a non-imported function template. A definition must
527 // be declared inline.
528 template<> __declspec(dllimport
) void funcTmpl
<ExplicitSpec_Imported
>();
529 template<> __declspec(dllimport
) void funcTmpl
<ExplicitSpec_Def_Imported
>() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
531 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
533 template<> __declspec(dllimport
) inline void funcTmpl
<ExplicitSpec_InlineDef_Imported
>() {}
536 //===----------------------------------------------------------------------===//
538 //===----------------------------------------------------------------------===//
540 // Import individual members of a class.
541 struct ImportMembers
{
543 __declspec(dllimport
) void normalDecl();
545 // expected-note@+2{{previous attribute is here}}
547 __declspec(dllimport
) void normalDef(); // expected-note{{previous declaration is here}}
551 // expected-note@+5{{previous attribute is here}}
552 // expected-warning@+5{{'dllimport' attribute ignored on inline function}}
553 // expected-warning@+6{{'dllimport' attribute ignored on inline function}}
555 __declspec(dllimport
) void normalDecl();
556 __declspec(dllimport
) void normalDef(); // expected-note{{previous declaration is here}}
557 __declspec(dllimport
) void normalInclass() {}
558 __declspec(dllimport
) void normalInlineDef();
559 __declspec(dllimport
) inline void normalInlineDecl();
561 // expected-note@+5{{previous attribute is here}}
562 // expected-warning@+5{{'dllimport' attribute ignored on inline function}}
563 // expected-warning@+6{{'dllimport' attribute ignored on inline function}}
565 __declspec(dllimport
) virtual void virtualDecl();
566 __declspec(dllimport
) virtual void virtualDef(); // expected-note{{previous declaration is here}}
567 __declspec(dllimport
) virtual void virtualInclass() {}
568 __declspec(dllimport
) virtual void virtualInlineDef();
569 __declspec(dllimport
) virtual inline void virtualInlineDecl();
571 // expected-note@+5{{previous attribute is here}}
572 // expected-warning@+5{{'dllimport' attribute ignored on inline function}}
573 // expected-warning@+6{{'dllimport' attribute ignored on inline function}}
575 __declspec(dllimport
) static void staticDecl();
576 __declspec(dllimport
) static void staticDef(); // expected-note{{previous declaration is here}}
577 __declspec(dllimport
) static void staticInclass() {}
578 __declspec(dllimport
) static void staticInlineDef();
579 __declspec(dllimport
) static inline void staticInlineDecl();
582 __declspec(dllimport
) void protectedDecl();
584 __declspec(dllimport
) void privateDecl();
587 __declspec(dllimport
) int Field
; // expected-warning{{'dllimport' attribute only applies to}}
588 __declspec(dllimport
) static int StaticField
;
589 __declspec(dllimport
) static int StaticFieldDef
; // expected-note{{attribute is here}}
590 __declspec(dllimport
) static const int StaticConstField
;
591 __declspec(dllimport
) static const int StaticConstFieldDef
; // expected-note{{attribute is here}}
592 __declspec(dllimport
) static const int StaticConstFieldEqualInit
= 1;
593 __declspec(dllimport
) static const int StaticConstFieldBraceInit
{1};
594 __declspec(dllimport
) constexpr static int ConstexprField
= 1;
595 #if __cplusplus < 201703L && !defined(MS)
596 // expected-note@+2{{attribute is here}}
598 __declspec(dllimport
) constexpr static int ConstexprFieldDef
= 1;
601 #if defined(MS) || defined(WI) || defined(PS)
602 // expected-warning@+4{{'ImportMembers::Nested::normalDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
604 // expected-warning@+2{{'ImportMembers::Nested::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
606 void ImportMembers::Nested::normalDef() {}
607 #if defined(MS) || defined(WI) || defined(PS)
608 // expected-warning@+4{{'ImportMembers::normalDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
610 // expected-warning@+2{{'ImportMembers::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
612 void ImportMembers::normalDef() {}
614 // expected-warning@+2{{'ImportMembers::normalInlineDef' redeclared inline; 'dllimport' attribute ignored}}
616 inline void ImportMembers::normalInlineDef() {}
617 void ImportMembers::normalInlineDecl() {}
618 #if defined(MS) || defined(WI) || defined(PS)
619 // expected-warning@+4{{'ImportMembers::virtualDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
621 // expected-warning@+2{{'ImportMembers::virtualDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
623 void ImportMembers::virtualDef() {}
625 // expected-warning@+2{{'ImportMembers::virtualInlineDef' redeclared inline; 'dllimport' attribute ignored}}
627 inline void ImportMembers::virtualInlineDef() {}
628 void ImportMembers::virtualInlineDecl() {}
629 #if defined(MS) || defined(WI) || defined(PS)
630 // expected-warning@+4{{'ImportMembers::staticDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
632 // expected-warning@+2{{'ImportMembers::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
634 void ImportMembers::staticDef() {}
636 // expected-warning@+2{{'ImportMembers::staticInlineDef' redeclared inline; 'dllimport' attribute ignored}}
638 inline void ImportMembers::staticInlineDef() {}
639 void ImportMembers::staticInlineDecl() {}
641 int ImportMembers::StaticFieldDef
; // expected-error{{definition of dllimport static field not allowed}}
642 const int ImportMembers::StaticConstFieldDef
= 1; // expected-error{{definition of dllimport static field not allowed}}
643 #if __cplusplus < 201703L && !defined(MS)
644 // expected-error@+2{{definition of dllimport static field not allowed}}
646 constexpr int ImportMembers::ConstexprFieldDef
;
649 // Import on member definitions.
650 struct ImportMemberDefs
{
651 __declspec(dllimport
) void normalDef();
652 __declspec(dllimport
) void normalInlineDef();
653 __declspec(dllimport
) virtual void virtualDef();
654 __declspec(dllimport
) virtual void virtualInlineDef();
655 __declspec(dllimport
) static void staticDef();
656 __declspec(dllimport
) static void staticInlineDef();
658 __declspec(dllimport
) inline void normalInlineDecl();
659 __declspec(dllimport
) virtual inline void virtualInlineDecl();
660 __declspec(dllimport
) static inline void staticInlineDecl();
663 __declspec(dllimport
) static int StaticField
;
664 __declspec(dllimport
) static const int StaticConstField
;
665 __declspec(dllimport
) constexpr static int ConstexprField
= 1;
668 __declspec(dllimport
) void ImportMemberDefs::normalDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
669 __declspec(dllimport
) void ImportMemberDefs::virtualDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
670 __declspec(dllimport
) void ImportMemberDefs::staticDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
672 __declspec(dllimport
) inline void ImportMemberDefs::normalInlineDef() {}
673 __declspec(dllimport
) void ImportMemberDefs::normalInlineDecl() {}
674 __declspec(dllimport
) inline void ImportMemberDefs::virtualInlineDef() {}
675 __declspec(dllimport
) void ImportMemberDefs::virtualInlineDecl() {}
676 __declspec(dllimport
) inline void ImportMemberDefs::staticInlineDef() {}
677 __declspec(dllimport
) void ImportMemberDefs::staticInlineDecl() {}
680 __declspec(dllimport
) int ImportMemberDefs::StaticField
; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}}
681 __declspec(dllimport
) const int ImportMemberDefs::StaticConstField
= 1; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}}
682 #if __cplusplus < 201703L && !defined(MS)
683 // expected-error@+3{{definition of dllimport static field not allowed}}
684 // expected-note@+2{{attribute is here}}
686 __declspec(dllimport
) constexpr int ImportMemberDefs::ConstexprField
;
689 // Import special member functions.
690 struct ImportSpecials
{
691 __declspec(dllimport
) ImportSpecials();
692 __declspec(dllimport
) ~ImportSpecials();
693 __declspec(dllimport
) ImportSpecials(const ImportSpecials
&);
694 __declspec(dllimport
) ImportSpecials
& operator=(const ImportSpecials
&);
695 __declspec(dllimport
) ImportSpecials(ImportSpecials
&&);
696 __declspec(dllimport
) ImportSpecials
& operator=(ImportSpecials
&&);
700 // Import deleted member functions.
701 struct ImportDeleted
{
702 #if defined(MS) || defined(WI) || defined(PS)
703 __declspec(dllimport
) ImportDeleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
704 __declspec(dllimport
) ~ImportDeleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
705 __declspec(dllimport
) ImportDeleted(const ImportDeleted
&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
706 __declspec(dllimport
) ImportDeleted
& operator=(const ImportDeleted
&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
707 __declspec(dllimport
) ImportDeleted(ImportDeleted
&&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
708 __declspec(dllimport
) ImportDeleted
& operator=(ImportDeleted
&&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
709 __declspec(dllimport
) void deleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
711 __declspec(dllimport
) ImportDeleted() = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
712 __declspec(dllimport
) ~ImportDeleted() = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
713 __declspec(dllimport
) ImportDeleted(const ImportDeleted
&) = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
714 __declspec(dllimport
) ImportDeleted
& operator=(const ImportDeleted
&) = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
715 __declspec(dllimport
) ImportDeleted(ImportDeleted
&&) = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
716 __declspec(dllimport
) ImportDeleted
& operator=(ImportDeleted
&&) = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
717 __declspec(dllimport
) void deleted() = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
722 // Import allocation functions.
724 __declspec(dllimport
) void* operator new(__SIZE_TYPE__
);
725 __declspec(dllimport
) void* operator new[](__SIZE_TYPE__
);
726 __declspec(dllimport
) void operator delete(void*);
727 __declspec(dllimport
) void operator delete[](void*);
731 // Import defaulted member functions.
732 struct ImportDefaulted
{
734 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
735 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
736 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
737 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
738 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
739 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
741 __declspec(dllimport
) ImportDefaulted() = default;
742 __declspec(dllimport
) ~ImportDefaulted() = default;
743 __declspec(dllimport
) ImportDefaulted(const ImportDefaulted
&) = default;
744 __declspec(dllimport
) ImportDefaulted
& operator=(const ImportDefaulted
&) = default;
745 __declspec(dllimport
) ImportDefaulted(ImportDefaulted
&&) = default;
746 __declspec(dllimport
) ImportDefaulted
& operator=(ImportDefaulted
&&) = default;
750 // Import defaulted member function definitions.
751 struct ImportDefaultedDefs
{
752 __declspec(dllimport
) ImportDefaultedDefs();
754 // expected-note@+2{{previous attribute is here}}
756 __declspec(dllimport
) ~ImportDefaultedDefs(); // expected-note{{previous declaration is here}}
759 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
760 // expected-note@+2{{previous declaration is here}}
762 __declspec(dllimport
) inline ImportDefaultedDefs(const ImportDefaultedDefs
&);
763 __declspec(dllimport
) ImportDefaultedDefs
& operator=(const ImportDefaultedDefs
&);
765 __declspec(dllimport
) ImportDefaultedDefs(ImportDefaultedDefs
&&);
767 // expected-note@+2{{previous attribute is here}}
769 __declspec(dllimport
) ImportDefaultedDefs
&operator=(ImportDefaultedDefs
&&); // expected-note{{previous declaration is here}}
772 // Not allowed on definitions.
773 __declspec(dllimport
) ImportDefaultedDefs::ImportDefaultedDefs() = default; // expected-error{{dllimport cannot be applied to non-inline function definition}}
775 #if defined(MS) || defined(WI) || defined(PS)
776 // expected-warning@+5{{'ImportDefaultedDefs::~ImportDefaultedDefs' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
778 // expected-warning@+3{{'ImportDefaultedDefs::~ImportDefaultedDefs' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
780 // dllimport cannot be dropped.
781 ImportDefaultedDefs::~ImportDefaultedDefs() = default;
783 // Import inline declaration and definition.
785 // expected-error@+3{{redeclaration of 'ImportDefaultedDefs::ImportDefaultedDefs' cannot add 'dllimport' attribute}}
786 // expected-warning@+3{{'ImportDefaultedDefs::operator=' redeclared inline; 'dllimport' attribute ignored}}
788 __declspec(dllimport
) ImportDefaultedDefs::ImportDefaultedDefs(const ImportDefaultedDefs
&) = default;
789 inline ImportDefaultedDefs
& ImportDefaultedDefs::operator=(const ImportDefaultedDefs
&) = default;
791 __declspec(dllimport
) ImportDefaultedDefs::ImportDefaultedDefs(ImportDefaultedDefs
&&) = default; // expected-error{{dllimport cannot be applied to non-inline function definition}}
792 #if defined(MS) || defined(WI) || defined(PS)
793 // expected-warning@+4{{'ImportDefaultedDefs::operator=' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
795 // expected-warning@+2{{'ImportDefaultedDefs::operator=' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
797 ImportDefaultedDefs
&ImportDefaultedDefs::operator=(ImportDefaultedDefs
&&) = default;
799 // Redeclarations cannot add dllimport.
800 struct MemberRedecl
{
801 void normalDef(); // expected-note{{previous declaration is here}}
802 inline void normalInlineDecl(); // expected-note{{previous declaration is here}}
803 virtual void virtualDef(); // expected-note{{previous declaration is here}}
804 virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}}
805 static void staticDef(); // expected-note{{previous declaration is here}}
806 static inline void staticInlineDecl(); // expected-note{{previous declaration is here}}
808 #if defined(MS) || defined(WI) || defined(PS)
809 // expected-note@+4{{previous declaration is here}}
810 // expected-note@+4{{previous declaration is here}}
811 // expected-note@+4{{previous declaration is here}}
813 void normalInlineDef();
814 virtual void virtualInlineDef();
815 static void staticInlineDef();
817 static int StaticField
; // expected-note{{previous declaration is here}}
818 static const int StaticConstField
; // expected-note{{previous declaration is here}}
819 constexpr static int ConstexprField
= 1; // expected-note-re{{previous {{(declaration|definition)}} is here}}
822 __declspec(dllimport
) void MemberRedecl::normalDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalDef' cannot add 'dllimport' attribute}}
823 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
824 __declspec(dllimport
) void MemberRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDecl' cannot add 'dllimport' attribute}}
825 __declspec(dllimport
) void MemberRedecl::virtualDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualDef' cannot add 'dllimport' attribute}}
826 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
827 __declspec(dllimport
) void MemberRedecl::virtualInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDecl' cannot add 'dllimport' attribute}}
828 __declspec(dllimport
) void MemberRedecl::staticDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticDef' cannot add 'dllimport' attribute}}
829 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
830 __declspec(dllimport
) void MemberRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDecl' cannot add 'dllimport' attribute}}
832 #if defined(MS) || defined(WI) || defined(PS)
833 __declspec(dllimport
) inline void MemberRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDef' cannot add 'dllimport' attribute}}
834 __declspec(dllimport
) inline void MemberRedecl::virtualInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDef' cannot add 'dllimport' attribute}}
835 __declspec(dllimport
) inline void MemberRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDef' cannot add 'dllimport' attribute}}
837 __declspec(dllimport
) inline void MemberRedecl::normalInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
838 __declspec(dllimport
) inline void MemberRedecl::virtualInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
839 __declspec(dllimport
) inline void MemberRedecl::staticInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
844 __declspec(dllimport
) int MemberRedecl::StaticField
= 1; // expected-error{{redeclaration of 'MemberRedecl::StaticField' cannot add 'dllimport' attribute}}
845 // expected-error@-1{{definition of dllimport static field not allowed}}
846 // expected-note@-2{{attribute is here}}
847 __declspec(dllimport
) const int MemberRedecl::StaticConstField
= 1; // expected-error{{redeclaration of 'MemberRedecl::StaticConstField' cannot add 'dllimport' attribute}}
848 // expected-error@-1{{definition of dllimport static field not allowed}}
849 // expected-note@-2{{attribute is here}}
851 #if __cplusplus < 201703L && !defined(MS)
852 // expected-error@+6{{redeclaration of 'MemberRedecl::ConstexprField' cannot add 'dllimport' attribute}}
853 // expected-error@+5{{definition of dllimport static field not allowed}}
854 // expected-note@+4{{attribute is here}}
856 // expected-warning@+2{{attribute declaration must precede definition}}
858 __declspec(dllimport
) constexpr int MemberRedecl::ConstexprField
;
862 //===----------------------------------------------------------------------===//
863 // Class member templates
864 //===----------------------------------------------------------------------===//
866 struct ImportMemberTmpl
{
867 template<typename T
> __declspec(dllimport
) void normalDecl();
868 template<typename T
> __declspec(dllimport
) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
869 #if defined(MS) || defined(WI) || defined(PS)
870 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
872 template<typename T
> __declspec(dllimport
) void normalInlineDef();
873 template<typename T
> __declspec(dllimport
) static void staticDecl();
874 template<typename T
> __declspec(dllimport
) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
875 #if defined(MS) || defined(WI) || defined(PS)
876 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
878 template<typename T
> __declspec(dllimport
) static void staticInlineDef();
881 template<typename T
> __declspec(dllimport
) void normalInclass() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
882 template<typename T
> __declspec(dllimport
) inline void normalInlineDecl(); // expected-warning{{'dllimport' attribute ignored on inline function}}
883 template<typename T
> __declspec(dllimport
) static void staticInclass() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
884 template<typename T
> __declspec(dllimport
) static inline void staticInlineDecl(); // expected-warning{{'dllimport' attribute ignored on inline function}}
886 template<typename T
> __declspec(dllimport
) void normalInclass() {}
887 template<typename T
> __declspec(dllimport
) inline void normalInlineDecl(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
888 template<typename T
> __declspec(dllimport
) static void staticInclass() {}
889 template<typename T
> __declspec(dllimport
) static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
892 #if __has_feature(cxx_variable_templates)
893 template<typename T
> __declspec(dllimport
) static int StaticField
;
894 template<typename T
> __declspec(dllimport
) static int StaticFieldDef
; // expected-note{{attribute is here}}
895 template<typename T
> __declspec(dllimport
) static const int StaticConstField
;
896 template<typename T
> __declspec(dllimport
) static const int StaticConstFieldDef
; // expected-note{{attribute is here}}
897 template<typename T
> __declspec(dllimport
) static const int StaticConstFieldEqualInit
= 1;
898 template<typename T
> __declspec(dllimport
) static const int StaticConstFieldBraceInit
{1};
899 template<typename T
> __declspec(dllimport
) constexpr static int ConstexprField
= 1;
900 template<typename T
> __declspec(dllimport
) constexpr static int ConstexprFieldDef
= 1;
901 #endif // __has_feature(cxx_variable_templates)
904 template<typename T
> void ImportMemberTmpl::normalDef() {} // expected-warning{{'ImportMemberTmpl::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
905 template<typename T
> void ImportMemberTmpl::staticDef() {} // expected-warning{{'ImportMemberTmpl::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
906 #ifdef GNU // dllimport was ignored above
907 template<typename T
> void ImportMemberTmpl::normalInlineDecl() {}
908 template<typename T
> void ImportMemberTmpl::staticInlineDecl() {}
909 #else // dllimport dropped here
910 template<typename T
> void ImportMemberTmpl::normalInlineDecl() {} // expected-warning{{'ImportMemberTmpl::normalInlineDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
911 template<typename T
> void ImportMemberTmpl::staticInlineDecl() {} // expected-warning{{'ImportMemberTmpl::staticInlineDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
915 template<typename T
> inline void ImportMemberTmpl::normalInlineDef() {} // expected-warning{{ImportMemberTmpl::normalInlineDef' redeclared inline; 'dllimport' attribute ignored}}
916 template<typename T
> inline void ImportMemberTmpl::staticInlineDef() {} // expected-warning{{ImportMemberTmpl::staticInlineDef' redeclared inline; 'dllimport' attribute ignored}}
918 template<typename T
> inline void ImportMemberTmpl::normalInlineDef() {} // expected-warning{{ImportMemberTmpl::normalInlineDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
919 template<typename T
> inline void ImportMemberTmpl::staticInlineDef() {} // expected-warning{{ImportMemberTmpl::staticInlineDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
922 #if __has_feature(cxx_variable_templates)
923 template<typename T
> int ImportMemberTmpl::StaticFieldDef
; // expected-error{{definition of dllimport static field not allowed}}
924 template<typename T
> const int ImportMemberTmpl::StaticConstFieldDef
= 1; // expected-error{{definition of dllimport static field not allowed}}
926 template<typename T
> constexpr int ImportMemberTmpl::ConstexprFieldDef
;
928 #endif // __has_feature(cxx_variable_templates)
931 // Redeclarations cannot add dllimport.
932 struct MemTmplRedecl
{
933 template<typename T
> void normalDef(); // expected-note{{previous declaration is here}}
934 template<typename T
> inline void normalInlineDecl(); // expected-note{{previous declaration is here}}
935 template<typename T
> static void staticDef(); // expected-note{{previous declaration is here}}
936 template<typename T
> static inline void staticInlineDecl(); // expected-note{{previous declaration is here}}
938 #if defined(MS) || defined(WI) || defined(PS)
939 // expected-note@+3{{previous declaration is here}}
940 // expected-note@+3{{previous declaration is here}}
942 template<typename T
> void normalInlineDef();
943 template<typename T
> static void staticInlineDef();
945 #if __has_feature(cxx_variable_templates)
946 template<typename T
> static int StaticField
; // expected-note{{previous declaration is here}}
947 template<typename T
> static const int StaticConstField
; // expected-note{{previous declaration is here}}
949 template<typename T
> constexpr static int ConstexprField
= 1; // expected-note{{previous definition is here}}
951 #endif // __has_feature(cxx_variable_templates)
954 template<typename T
> __declspec(dllimport
) void MemTmplRedecl::normalDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalDef' cannot add 'dllimport' attribute}}
955 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
956 #if defined(MS) || defined(WI) || defined(PS)
957 template<typename T
> __declspec(dllimport
) inline void MemTmplRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDef' cannot add 'dllimport' attribute}}
959 template<typename T
> __declspec(dllimport
) inline void MemTmplRedecl::normalInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
961 template<typename T
> __declspec(dllimport
) void MemTmplRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDecl' cannot add 'dllimport' attribute}}
962 template<typename T
> __declspec(dllimport
) void MemTmplRedecl::staticDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticDef' cannot add 'dllimport' attribute}}
963 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
964 #if defined(MS) || defined(WI) || defined(PS)
965 template<typename T
> __declspec(dllimport
) inline void MemTmplRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDef' cannot add 'dllimport' attribute}}
967 template<typename T
> __declspec(dllimport
) inline void MemTmplRedecl::staticInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
969 template<typename T
> __declspec(dllimport
) void MemTmplRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDecl' cannot add 'dllimport' attribute}}
971 #if __has_feature(cxx_variable_templates)
972 template<typename T
> __declspec(dllimport
) int MemTmplRedecl::StaticField
= 1; // expected-error{{redeclaration of 'MemTmplRedecl::StaticField' cannot add 'dllimport' attribute}}
973 // expected-error@-1{{definition of dllimport static field not allowed}}
974 // expected-note@-2{{attribute is here}}
975 template<typename T
> __declspec(dllimport
) const int MemTmplRedecl::StaticConstField
= 1; // expected-error{{redeclaration of 'MemTmplRedecl::StaticConstField' cannot add 'dllimport' attribute}}
976 // expected-error@-1{{definition of dllimport static field not allowed}}
977 // expected-note@-2{{attribute is here}}
979 // expected-warning@+1{{attribute declaration must precede definition}}
980 template<typename T
> __declspec(dllimport
) constexpr int MemTmplRedecl::ConstexprField
;
982 #endif // __has_feature(cxx_variable_templates)
987 template<typename T
> void normalDef() {}
989 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
991 template<typename T
> __declspec(dllimport
) void importedNormal() {}
992 template<typename T
> static void staticDef() {}
994 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
996 template<typename T
> __declspec(dllimport
) static void importedStatic() {}
999 // Import implicit instantiation of an imported member function template.
1000 void useMemFunTmpl() {
1001 MemFunTmpl().importedNormal
<ImplicitInst_Imported
>();
1002 MemFunTmpl().importedStatic
<ImplicitInst_Imported
>();
1005 // Import explicit instantiation declaration of an imported member function
1007 extern template void MemFunTmpl::importedNormal
<ExplicitDecl_Imported
>();
1008 extern template void MemFunTmpl::importedStatic
<ExplicitDecl_Imported
>();
1010 // Import explicit instantiation definition of an imported member function
1012 // NB: MSVC fails this instantiation without explicit dllimport.
1013 template void MemFunTmpl::importedNormal
<ExplicitInst_Imported
>();
1014 template void MemFunTmpl::importedStatic
<ExplicitInst_Imported
>();
1016 // Import specialization of an imported member function template.
1017 template<> __declspec(dllimport
) void MemFunTmpl::importedNormal
<ExplicitSpec_Imported
>();
1018 template<> __declspec(dllimport
) void MemFunTmpl::importedNormal
<ExplicitSpec_Def_Imported
>() {} // error on mingw
1020 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1022 template<> __declspec(dllimport
) inline void MemFunTmpl::importedNormal
<ExplicitSpec_InlineDef_Imported
>() {}
1024 // FIXME: This should not be an error when targeting MSVC. (PR21406)
1025 // expected-error@-7{{dllimport cannot be applied to non-inline function definition}}
1028 template<> __declspec(dllimport
) void MemFunTmpl::importedStatic
<ExplicitSpec_Imported
>();
1029 template<> __declspec(dllimport
) void MemFunTmpl::importedStatic
<ExplicitSpec_Def_Imported
>() {} // error on mingw
1031 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1033 template<> __declspec(dllimport
) inline void MemFunTmpl::importedStatic
<ExplicitSpec_InlineDef_Imported
>() {}
1035 // FIXME: This should not be an error when targeting MSVC. (PR21406)
1036 // expected-error@-7{{dllimport cannot be applied to non-inline function definition}}
1039 // Not importing specialization of an imported member function template without
1040 // explicit dllimport.
1041 template<> void MemFunTmpl::importedNormal
<ExplicitSpec_NotImported
>() {}
1042 template<> void MemFunTmpl::importedStatic
<ExplicitSpec_NotImported
>() {}
1045 // Import explicit instantiation declaration of a non-imported member function
1048 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
1049 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
1051 extern template __declspec(dllimport
) void MemFunTmpl::normalDef
<ExplicitDecl_Imported
>();
1052 extern template __declspec(dllimport
) void MemFunTmpl::staticDef
<ExplicitDecl_Imported
>();
1054 // Import explicit instantiation definition of a non-imported member function
1057 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
1058 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
1060 template __declspec(dllimport
) void MemFunTmpl::normalDef
<ExplicitInst_Imported
>();
1061 template __declspec(dllimport
) void MemFunTmpl::staticDef
<ExplicitInst_Imported
>();
1063 // Import specialization of a non-imported member function template.
1064 template<> __declspec(dllimport
) void MemFunTmpl::normalDef
<ExplicitSpec_Imported
>();
1065 template<> __declspec(dllimport
) void MemFunTmpl::normalDef
<ExplicitSpec_Def_Imported
>() {} // error on mingw
1067 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1069 template<> __declspec(dllimport
) inline void MemFunTmpl::normalDef
<ExplicitSpec_InlineDef_Imported
>() {}
1071 // FIXME: This should not be an error when targeting MSVC. (PR21406)
1072 // expected-error@-7{{dllimport cannot be applied to non-inline function definition}}
1075 template<> __declspec(dllimport
) void MemFunTmpl::staticDef
<ExplicitSpec_Imported
>();
1076 template<> __declspec(dllimport
) void MemFunTmpl::staticDef
<ExplicitSpec_Def_Imported
>() {} // error on mingw
1078 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1080 template<> __declspec(dllimport
) inline void MemFunTmpl::staticDef
<ExplicitSpec_InlineDef_Imported
>() {}
1082 // FIXME: This should not be an error when targeting MSVC. (PR21406)
1083 // expected-error@-7{{dllimport cannot be applied to non-inline function definition}}
1088 #if __has_feature(cxx_variable_templates)
1090 template<typename T
> static const int StaticVar
= 1;
1091 template<typename T
> __declspec(dllimport
) static const int ImportedStaticVar
= 1;
1094 // Import implicit instantiation of an imported member variable template.
1095 int useMemVarTmpl() { return MemVarTmpl::ImportedStaticVar
<ImplicitInst_Imported
>; }
1097 // Import explicit instantiation declaration of an imported member variable
1099 extern template const int MemVarTmpl::ImportedStaticVar
<ExplicitDecl_Imported
>;
1101 // An explicit instantiation definition of an imported member variable template
1102 // cannot be imported because the template must be defined which is illegal. The
1103 // in-class initializer does not count.
1105 // Import specialization of an imported member variable template.
1106 template<> __declspec(dllimport
) const int MemVarTmpl::ImportedStaticVar
<ExplicitSpec_Imported
>;
1107 template<> __declspec(dllimport
) const int MemVarTmpl::ImportedStaticVar
<ExplicitSpec_Def_Imported
> = 1;
1108 // expected-error@-1{{definition of dllimport static field not allowed}}
1109 // expected-note@-2{{attribute is here}}
1111 // Not importing specialization of a member variable template without explicit
1113 template<> const int MemVarTmpl::ImportedStaticVar
<ExplicitSpec_NotImported
>;
1116 // Import explicit instantiation declaration of a non-imported member variable
1118 extern template __declspec(dllimport
) const int MemVarTmpl::StaticVar
<ExplicitDecl_Imported
>;
1120 // An explicit instantiation definition of a non-imported member variable template
1121 // cannot be imported because the template must be defined which is illegal. The
1122 // in-class initializer does not count.
1124 // Import specialization of a non-imported member variable template.
1125 template<> __declspec(dllimport
) const int MemVarTmpl::StaticVar
<ExplicitSpec_Imported
>;
1126 template<> __declspec(dllimport
) const int MemVarTmpl::StaticVar
<ExplicitSpec_Def_Imported
> = 1;
1127 // expected-error@-1{{definition of dllimport static field not allowed}}
1128 // expected-note@-2{{attribute is here}}
1130 #endif // __has_feature(cxx_variable_templates)
1134 //===----------------------------------------------------------------------===//
1135 // Class template members
1136 //===----------------------------------------------------------------------===//
1138 // Import individual members of a class template.
1139 template<typename T
>
1140 struct ImportClassTmplMembers
{
1142 // expected-note@+2{{attribute is here}}
1144 __declspec(dllimport
) void normalDecl();
1146 // expected-note@+2{{previous attribute is here}}
1148 __declspec(dllimport
) void normalDef(); // expected-note{{previous declaration is here}}
1149 __declspec(dllimport
) void normalInlineDef();
1150 __declspec(dllimport
) virtual void virtualDecl();
1152 // expected-note@+2{{previous attribute is here}}
1154 __declspec(dllimport
) virtual void virtualDef(); // expected-note{{previous declaration is here}}
1155 __declspec(dllimport
) virtual void virtualInlineDef();
1156 __declspec(dllimport
) static void staticDecl();
1158 // expected-note@+2{{previous attribute is here}}
1160 __declspec(dllimport
) static void staticDef(); // expected-note{{previous declaration is here}}
1161 __declspec(dllimport
) static void staticInlineDef();
1164 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1165 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1166 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1167 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1168 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1169 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1171 __declspec(dllimport
) void normalInclass() {}
1172 __declspec(dllimport
) inline void normalInlineDecl();
1173 __declspec(dllimport
) virtual void virtualInclass() {}
1174 __declspec(dllimport
) virtual inline void virtualInlineDecl();
1175 __declspec(dllimport
) static void staticInclass() {}
1176 __declspec(dllimport
) static inline void staticInlineDecl();
1179 __declspec(dllimport
) void protectedDecl();
1181 __declspec(dllimport
) void privateDecl();
1184 __declspec(dllimport
) int Field
; // expected-warning{{'dllimport' attribute only applies to}}
1185 __declspec(dllimport
) static int StaticField
;
1186 __declspec(dllimport
) static int StaticFieldDef
; // expected-note{{attribute is here}}
1187 __declspec(dllimport
) static const int StaticConstField
;
1188 __declspec(dllimport
) static const int StaticConstFieldDef
; // expected-note{{attribute is here}}
1189 __declspec(dllimport
) static const int StaticConstFieldEqualInit
= 1;
1190 __declspec(dllimport
) static const int StaticConstFieldBraceInit
{1};
1191 __declspec(dllimport
) constexpr static int ConstexprField
= 1;
1192 #if __cplusplus < 201703L && !defined(MS)
1193 // expected-note@+2{{attribute is here}}
1195 __declspec(dllimport
) constexpr static int ConstexprFieldDef
= 1;
1198 // NB: MSVC is inconsistent here and disallows *InlineDef on class templates,
1199 // but allows it on classes. We allow both.
1200 #if defined(MS) || defined(WI) || defined(PS)
1201 // expected-warning@+5{{'ImportClassTmplMembers::normalDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
1203 // expected-warning@+3{{'ImportClassTmplMembers::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1205 template <typename T
>
1206 void ImportClassTmplMembers
<T
>::normalDef() {}
1208 // expected-warning@+2{{'ImportClassTmplMembers::normalInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1210 template<typename T
> inline void ImportClassTmplMembers
<T
>::normalInlineDef() {}
1211 template<typename T
> void ImportClassTmplMembers
<T
>::normalInlineDecl() {}
1212 #if defined(MS) || defined(WI) || defined(PS)
1213 // expected-warning@+5{{'ImportClassTmplMembers::virtualDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
1215 // expected-warning@+3{{'ImportClassTmplMembers::virtualDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1217 template <typename T
>
1218 void ImportClassTmplMembers
<T
>::virtualDef() {}
1220 // expected-warning@+2{{'ImportClassTmplMembers::virtualInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1222 template<typename T
> inline void ImportClassTmplMembers
<T
>::virtualInlineDef() {}
1223 template<typename T
> void ImportClassTmplMembers
<T
>::virtualInlineDecl() {}
1224 #if defined(MS) || defined(WI) || defined(PS)
1225 // expected-warning@+5{{'ImportClassTmplMembers::staticDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
1227 // expected-warning@+3{{'ImportClassTmplMembers::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1229 template <typename T
>
1230 void ImportClassTmplMembers
<T
>::staticDef() {}
1232 // expected-warning@+2{{'ImportClassTmplMembers::staticInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1234 template<typename T
> inline void ImportClassTmplMembers
<T
>::staticInlineDef() {}
1235 template<typename T
> void ImportClassTmplMembers
<T
>::staticInlineDecl() {}
1237 template<typename T
> int ImportClassTmplMembers
<T
>::StaticFieldDef
; // expected-warning{{definition of dllimport static field}}
1238 template<typename T
> const int ImportClassTmplMembers
<T
>::StaticConstFieldDef
= 1; // expected-warning{{definition of dllimport static field}}
1239 #if __cplusplus < 201703L && !defined(MS)
1240 // expected-warning@+2{{definition of dllimport static field}}
1242 template<typename T
> constexpr int ImportClassTmplMembers
<T
>::ConstexprFieldDef
;
1245 // Redeclarations cannot add dllimport.
1246 template<typename T
>
1247 struct CTMR
/*ClassTmplMemberRedecl*/ {
1248 void normalDef(); // expected-note{{previous declaration is here}}
1249 inline void normalInlineDecl(); // expected-note{{previous declaration is here}}
1250 virtual void virtualDef(); // expected-note{{previous declaration is here}}
1251 virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}}
1252 static void staticDef(); // expected-note{{previous declaration is here}}
1253 static inline void staticInlineDecl(); // expected-note{{previous declaration is here}}
1255 #if defined(MS) || defined(WI) || defined(PS)
1256 // expected-note@+4{{previous declaration is here}}
1257 // expected-note@+4{{previous declaration is here}}
1258 // expected-note@+4{{previous declaration is here}}
1260 void normalInlineDef();
1261 virtual void virtualInlineDef();
1262 static void staticInlineDef();
1264 static int StaticField
; // expected-note{{previous declaration is here}}
1265 static const int StaticConstField
; // expected-note{{previous declaration is here}}
1266 constexpr static int ConstexprField
= 1; // expected-note-re{{previous {{(declaration|definition)}} is here}}
1269 template<typename T
> __declspec(dllimport
) void CTMR
<T
>::normalDef() {} // expected-error{{redeclaration of 'CTMR::normalDef' cannot add 'dllimport' attribute}}
1270 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
1271 template<typename T
> __declspec(dllimport
) void CTMR
<T
>::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMR::normalInlineDecl' cannot add 'dllimport' attribute}}
1272 template<typename T
> __declspec(dllimport
) void CTMR
<T
>::virtualDef() {} // expected-error{{redeclaration of 'CTMR::virtualDef' cannot add 'dllimport' attribute}}
1273 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
1274 template<typename T
> __declspec(dllimport
) void CTMR
<T
>::virtualInlineDecl() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDecl' cannot add 'dllimport' attribute}}
1275 template<typename T
> __declspec(dllimport
) void CTMR
<T
>::staticDef() {} // expected-error{{redeclaration of 'CTMR::staticDef' cannot add 'dllimport' attribute}}
1276 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
1277 template<typename T
> __declspec(dllimport
) void CTMR
<T
>::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMR::staticInlineDecl' cannot add 'dllimport' attribute}}
1279 #if defined(MS) || defined(WI) || defined(PS)
1280 template<typename T
> __declspec(dllimport
) inline void CTMR
<T
>::normalInlineDef() {} // expected-error{{redeclaration of 'CTMR::normalInlineDef' cannot add 'dllimport' attribute}}
1281 template<typename T
> __declspec(dllimport
) inline void CTMR
<T
>::virtualInlineDef() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDef' cannot add 'dllimport' attribute}}
1282 template<typename T
> __declspec(dllimport
) inline void CTMR
<T
>::staticInlineDef() {} // expected-error{{redeclaration of 'CTMR::staticInlineDef' cannot add 'dllimport' attribute}}
1284 template<typename T
> __declspec(dllimport
) inline void CTMR
<T
>::normalInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1285 template<typename T
> __declspec(dllimport
) inline void CTMR
<T
>::virtualInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1286 template<typename T
> __declspec(dllimport
) inline void CTMR
<T
>::staticInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1289 template<typename T
> __declspec(dllimport
) int CTMR
<T
>::StaticField
= 1; // expected-error{{redeclaration of 'CTMR::StaticField' cannot add 'dllimport' attribute}}
1290 // expected-warning@-1{{definition of dllimport static field}}
1291 // expected-note@-2{{attribute is here}}
1292 template<typename T
> __declspec(dllimport
) const int CTMR
<T
>::StaticConstField
= 1; // expected-error{{redeclaration of 'CTMR::StaticConstField' cannot add 'dllimport' attribute}}
1293 // expected-warning@-1{{definition of dllimport static field}}
1294 // expected-note@-2{{attribute is here}}
1296 #if __cplusplus < 201703L && !defined(MS)
1297 // expected-error@+6{{redeclaration of 'CTMR::ConstexprField' cannot add 'dllimport' attribute}}
1298 // expected-warning@+5{{definition of dllimport static field}}
1299 // expected-note@+4{{attribute is here}}
1301 // expected-warning@+2{{attribute declaration must precede definition}}
1303 template<typename T
> __declspec(dllimport
) constexpr int CTMR
<T
>::ConstexprField
;
1306 // MSVC imports explicit specialization of imported class template member
1307 // function, and errors on such definitions. MinGW does not treat them as
1309 template <typename
> struct ClassTmpl
{
1311 // expected-note@+2{{attribute is here}}
1313 void __declspec(dllimport
) importedNormal();
1315 // expected-note@+2{{attribute is here}}
1317 static void __declspec(dllimport
) importedStatic();
1320 // expected-error@+2{{cannot define non-inline dllimport template specialization}}
1322 template<> void ClassTmpl
<int>::importedNormal() {}
1324 // expected-error@+2{{cannot define non-inline dllimport template specialization}}
1326 template<> void ClassTmpl
<int>::importedStatic() {}
1329 // expected-error@+3{{cannot define non-inline dllimport template specialization}}
1330 // expected-error@+2{{attribute 'dllimport' cannot be applied to a deleted function}}
1332 template <> void ImportClassTmplMembers
<int>::normalDecl() = delete;
1335 //===----------------------------------------------------------------------===//
1336 // Class template member templates
1337 //===----------------------------------------------------------------------===//
1339 template<typename T
>
1340 struct ImportClsTmplMemTmpl
{
1341 template<typename U
> __declspec(dllimport
) void normalDecl();
1342 template<typename U
> __declspec(dllimport
) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
1343 #if defined(MS) || defined(WI) || defined(PS)
1344 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
1346 template<typename U
> __declspec(dllimport
) void normalInlineDef();
1347 template<typename U
> __declspec(dllimport
) static void staticDecl();
1348 template<typename U
> __declspec(dllimport
) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
1349 #if defined(MS) || defined(WI) || defined(PS)
1350 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
1352 template<typename U
> __declspec(dllimport
) static void staticInlineDef();
1355 // expected-warning@+5{{'dllimport' attribute ignored on inline function}}
1356 // expected-warning@+8{{'dllimport' attribute ignored on inline function}}
1357 // expected-warning@+8{{'dllimport' attribute ignored on inline function}}
1358 // expected-warning@+11{{'dllimport' attribute ignored on inline function}}
1360 template<typename U
> __declspec(dllimport
) void normalInclass() {}
1361 #if defined(MS) || defined(WI) || defined(PS)
1362 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
1364 template<typename U
> __declspec(dllimport
) inline void normalInlineDecl();
1365 template<typename U
> __declspec(dllimport
) static void staticInclass() {}
1366 #if defined(MS) || defined(WI) || defined(PS)
1367 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
1369 template<typename U
> __declspec(dllimport
) static inline void staticInlineDecl();
1371 #if __has_feature(cxx_variable_templates)
1372 template<typename U
> __declspec(dllimport
) static int StaticField
;
1373 template<typename U
> __declspec(dllimport
) static int StaticFieldDef
; // expected-note{{attribute is here}}
1374 template<typename U
> __declspec(dllimport
) static const int StaticConstField
;
1375 template<typename U
> __declspec(dllimport
) static const int StaticConstFieldDef
; // expected-note{{attribute is here}}
1376 template<typename U
> __declspec(dllimport
) static const int StaticConstFieldEqualInit
= 1;
1377 template<typename U
> __declspec(dllimport
) static const int StaticConstFieldBraceInit
{1};
1378 template<typename U
> __declspec(dllimport
) constexpr static int ConstexprField
= 1;
1380 template<typename U
> __declspec(dllimport
) constexpr static int ConstexprFieldDef
= 1;
1382 #endif // __has_feature(cxx_variable_templates)
1385 template<typename T
> template<typename U
> void ImportClsTmplMemTmpl
<T
>::normalDef() {} // expected-warning{{'ImportClsTmplMemTmpl::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1386 template<typename T
> template<typename U
> void ImportClsTmplMemTmpl
<T
>::staticDef() {} // expected-warning{{'ImportClsTmplMemTmpl::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1388 template<typename T
> template<typename U
> void ImportClsTmplMemTmpl
<T
>::normalInlineDecl() {}
1389 template<typename T
> template<typename U
> void ImportClsTmplMemTmpl
<T
>::staticInlineDecl() {}
1391 template<typename T
> template<typename U
> void ImportClsTmplMemTmpl
<T
>::normalInlineDecl() {} // expected-warning{{'ImportClsTmplMemTmpl::normalInlineDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1392 template<typename T
> template<typename U
> void ImportClsTmplMemTmpl
<T
>::staticInlineDecl() {} // expected-warning{{'ImportClsTmplMemTmpl::staticInlineDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1396 template<typename T
> template<typename U
> inline void ImportClsTmplMemTmpl
<T
>::normalInlineDef() {} // expected-warning{{'ImportClsTmplMemTmpl::normalInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1397 template<typename T
> template<typename U
> inline void ImportClsTmplMemTmpl
<T
>::staticInlineDef() {} // expected-warning{{'ImportClsTmplMemTmpl::staticInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1399 template<typename T
> template<typename U
> inline void ImportClsTmplMemTmpl
<T
>::normalInlineDef() {} // expected-warning{{'ImportClsTmplMemTmpl::normalInlineDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1400 template<typename T
> template<typename U
> inline void ImportClsTmplMemTmpl
<T
>::staticInlineDef() {} // expected-warning{{'ImportClsTmplMemTmpl::staticInlineDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1403 #if __has_feature(cxx_variable_templates)
1404 template<typename T
> template<typename U
> int ImportClsTmplMemTmpl
<T
>::StaticFieldDef
; // expected-warning{{definition of dllimport static field}}
1405 template<typename T
> template<typename U
> const int ImportClsTmplMemTmpl
<T
>::StaticConstFieldDef
= 1; // expected-warning{{definition of dllimport static field}}
1407 template<typename T
> template<typename U
> constexpr int ImportClsTmplMemTmpl
<T
>::ConstexprFieldDef
;
1409 #endif // __has_feature(cxx_variable_templates)
1412 // Redeclarations cannot add dllimport.
1413 template<typename T
>
1414 struct CTMTR
/*ClassTmplMemberTmplRedecl*/ {
1415 template<typename U
> void normalDef(); // expected-note{{previous declaration is here}}
1416 template<typename U
> inline void normalInlineDecl(); // expected-note{{previous declaration is here}}
1417 template<typename U
> static void staticDef(); // expected-note{{previous declaration is here}}
1418 template<typename U
> static inline void staticInlineDecl(); // expected-note{{previous declaration is here}}
1420 #if defined(MS) || defined(WI) || defined(PS)
1421 // expected-note@+3{{previous declaration is here}}
1422 // expected-note@+3{{previous declaration is here}}
1424 template<typename U
> void normalInlineDef();
1425 template<typename U
> static void staticInlineDef();
1427 #if __has_feature(cxx_variable_templates)
1428 template<typename U
> static int StaticField
; // expected-note{{previous declaration is here}}
1429 template<typename U
> static const int StaticConstField
; // expected-note{{previous declaration is here}}
1431 template<typename U
> constexpr static int ConstexprField
= 1; // expected-note{{previous definition is here}}
1433 #endif // __has_feature(cxx_variable_templates)
1436 template<typename T
> template<typename U
> __declspec(dllimport
) void CTMTR
<T
>::normalDef() {} // expected-error{{redeclaration of 'CTMTR::normalDef' cannot add 'dllimport' attribute}}
1437 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
1438 template<typename T
> template<typename U
> __declspec(dllimport
) void CTMTR
<T
>::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDecl' cannot add 'dllimport' attribute}}
1439 template<typename T
> template<typename U
> __declspec(dllimport
) void CTMTR
<T
>::staticDef() {} // expected-error{{redeclaration of 'CTMTR::staticDef' cannot add 'dllimport' attribute}}
1440 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
1441 template<typename T
> template<typename U
> __declspec(dllimport
) void CTMTR
<T
>::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDecl' cannot add 'dllimport' attribute}}
1443 #if defined(MS) || defined(WI) || defined(PS)
1444 template<typename T
> template<typename U
> __declspec(dllimport
) inline void CTMTR
<T
>::normalInlineDef() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDef' cannot add 'dllimport' attribute}}
1445 template<typename T
> template<typename U
> __declspec(dllimport
) inline void CTMTR
<T
>::staticInlineDef() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDef' cannot add 'dllimport' attribute}}
1447 template<typename T
> template<typename U
> __declspec(dllimport
) inline void CTMTR
<T
>::normalInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1448 template<typename T
> template<typename U
> __declspec(dllimport
) inline void CTMTR
<T
>::staticInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1451 #if __has_feature(cxx_variable_templates)
1452 template<typename T
> template<typename U
> __declspec(dllimport
) int CTMTR
<T
>::StaticField
= 1; // expected-error{{redeclaration of 'CTMTR::StaticField' cannot add 'dllimport' attribute}}
1453 // expected-warning@-1{{definition of dllimport static field}}
1454 // expected-note@-2{{attribute is here}}
1455 template<typename T
> template<typename U
> __declspec(dllimport
) const int CTMTR
<T
>::StaticConstField
= 1; // expected-error{{redeclaration of 'CTMTR::StaticConstField' cannot add 'dllimport' attribute}}
1456 // expected-warning@-1{{definition of dllimport static field}}
1457 // expected-note@-2{{attribute is here}}
1459 // expected-warning@+1{{attribute declaration must precede definition}}
1460 template<typename T
> template<typename U
> __declspec(dllimport
) constexpr int CTMTR
<T
>::ConstexprField
;
1462 #endif // __has_feature(cxx_variable_templates)
1466 //===----------------------------------------------------------------------===//
1468 //===----------------------------------------------------------------------===//
1471 struct __declspec(dllimport
) AnonymousClass
{}; // expected-error{{(anonymous namespace)::AnonymousClass' must have external linkage when declared 'dllimport'}}
1474 class __declspec(dllimport
) ClassDecl
;
1476 class __declspec(dllimport
) ClassDef
{ };
1478 template <typename T
> class ClassTemplate
{};
1480 #if defined(MS) || defined(WI) || defined(PS)
1481 // expected-note@+5{{previous attribute is here}}
1482 // expected-note@+4{{previous attribute is here}}
1483 // expected-error@+4{{attribute 'dllexport' cannot be applied to member of 'dllimport' class}}
1484 // expected-error@+4{{attribute 'dllimport' cannot be applied to member of 'dllimport' class}}
1486 class __declspec(dllimport
) ImportClassWithDllMember
{
1487 void __declspec(dllexport
) foo();
1488 void __declspec(dllimport
) bar();
1491 #if defined(MS) || defined(WI) || defined(PS)
1492 // expected-note@+5{{previous attribute is here}}
1493 // expected-note@+4{{previous attribute is here}}
1494 // expected-error@+4{{attribute 'dllimport' cannot be applied to member of 'dllexport' class}}
1495 // expected-error@+4{{attribute 'dllexport' cannot be applied to member of 'dllexport' class}}
1497 template <typename T
> class __declspec(dllexport
) ExportClassWithDllMember
{
1498 void __declspec(dllimport
) foo();
1499 void __declspec(dllexport
) bar();
1502 namespace ImportedExplicitSpecialization
{
1503 template <typename T
> struct S
{ static int x
; };
1504 template <typename T
> int S
<T
>::x
= sizeof(T
);
1505 template <> struct __declspec(dllimport
) S
<int> { static int x
; }; // expected-note{{attribute is here}}
1506 int S
<int>::x
= -1; // expected-error{{definition of dllimport static field not allowed}}
1510 // Don't error about applying delete to dllimport member function when instantiating.
1511 template <typename
> struct __declspec(dllimport
) S
{
1512 void foo() = delete;
1517 #if defined(MS) || defined(WI) || defined(PS)
1518 // expected-warning@+3{{'dllimport' attribute ignored}}
1520 template <typename T
> struct PartiallySpecializedClassTemplate
{};
1521 template <typename T
> struct __declspec(dllimport
) PartiallySpecializedClassTemplate
<T
*> { void f() {} };
1523 template <typename T
> struct ExpliciallySpecializedClassTemplate
{};
1524 template <> struct __declspec(dllimport
) ExpliciallySpecializedClassTemplate
<int> { void f() {} };
1527 //===----------------------------------------------------------------------===//
1528 // Classes with template base classes
1529 //===----------------------------------------------------------------------===//
1531 class __declspec(dllexport
) ExportedClass
{};
1532 class __declspec(dllimport
) ImportedClass
{};
1534 template <typename T
> class __declspec(dllexport
) ExportedClassTemplate
{};
1536 #if !defined(MS) && !defined(PS)
1537 // expected-error@+2{{'ImportedClassTemplate<LocalCRTP>' must have external linkage when declared 'dllimport'}}
1539 template <typename T
> class __declspec(dllimport
) ImportedClassTemplate
{};
1541 // ClassTemplate<int> gets imported.
1542 class __declspec(dllimport
) DerivedFromTemplate
: public ClassTemplate
<int> {};
1544 // ClassTemplate<int> is already imported.
1545 class __declspec(dllimport
) DerivedFromTemplate2
: public ClassTemplate
<int> {};
1547 // ImportedClassTemplate is expliitly imported.
1548 class __declspec(dllimport
) DerivedFromImportedTemplate
: public ImportedClassTemplate
<int> {};
1550 // ExportedClassTemplate is explicitly exported.
1551 class __declspec(dllimport
) DerivedFromExportedTemplate
: public ExportedClassTemplate
<int> {};
1553 class DerivedFromTemplateD
: public ClassTemplate
<double> {};
1554 // Base class previously implicitly instantiated without attribute; it will get propagated.
1555 class __declspec(dllimport
) DerivedFromTemplateD2
: public ClassTemplate
<double> {};
1557 // Base class has explicit instantiation declaration; the attribute will get propagated.
1558 extern template class ClassTemplate
<float>;
1559 class __declspec(dllimport
) DerivedFromTemplateF
: public ClassTemplate
<float> {};
1561 class __declspec(dllimport
) DerivedFromTemplateB
: public ClassTemplate
<bool> {};
1562 // The second derived class doesn't change anything, the attribute that was propagated first wins.
1563 class __declspec(dllexport
) DerivedFromTemplateB2
: public ClassTemplate
<bool> {};
1565 template <typename T
> struct ExplicitlySpecializedTemplate
{ void func() {} };
1566 #if defined(MS) || defined(PS)
1567 // expected-note@+2{{class template 'ExplicitlySpecializedTemplate<int>' was explicitly specialized here}}
1569 template <> struct ExplicitlySpecializedTemplate
<int> { void func() {} };
1570 template <typename T
> struct ExplicitlyExportSpecializedTemplate
{ void func() {} };
1571 template <> struct __declspec(dllexport
) ExplicitlyExportSpecializedTemplate
<int> { void func() {} };
1572 template <typename T
> struct ExplicitlyImportSpecializedTemplate
{ void func() {} };
1573 template <> struct __declspec(dllimport
) ExplicitlyImportSpecializedTemplate
<int> { void func() {} };
1575 template <typename T
> struct ExplicitlyInstantiatedTemplate
{ void func() {} };
1576 #if defined(MS) || defined(PS)
1577 // expected-note@+2{{class template 'ExplicitlyInstantiatedTemplate<int>' was instantiated here}}
1579 template struct ExplicitlyInstantiatedTemplate
<int>;
1580 template <typename T
> struct ExplicitlyExportInstantiatedTemplate
{ void func() {} };
1581 template struct __declspec(dllexport
) ExplicitlyExportInstantiatedTemplate
<int>;
1582 template <typename T
> struct ExplicitlyImportInstantiatedTemplate
{ void func() {} };
1583 template struct __declspec(dllimport
) ExplicitlyImportInstantiatedTemplate
<int>;
1585 #if defined(MS) || defined(PS)
1586 // expected-warning@+3{{propagating dll attribute to explicitly specialized base class template without dll attribute is not supported}}
1587 // expected-note@+2{{attribute is here}}
1589 struct __declspec(dllimport
) DerivedFromExplicitlySpecializedTemplate
: public ExplicitlySpecializedTemplate
<int> {};
1591 // Base class already specialized with export attribute.
1592 struct __declspec(dllimport
) DerivedFromExplicitlyExportSpecializedTemplate
: public ExplicitlyExportSpecializedTemplate
<int> {};
1594 // Base class already specialized with import attribute.
1595 struct __declspec(dllimport
) DerivedFromExplicitlyImportSpecializedTemplate
: public ExplicitlyImportSpecializedTemplate
<int> {};
1597 #if defined(MS) || defined(PS)
1598 // expected-warning@+3{{propagating dll attribute to already instantiated base class template without dll attribute is not supported}}
1599 // expected-note@+2{{attribute is here}}
1601 struct __declspec(dllimport
) DerivedFromExplicitlyInstantiatedTemplate
: public ExplicitlyInstantiatedTemplate
<int> {};
1603 // Base class already instantiated with export attribute.
1604 struct __declspec(dllimport
) DerivedFromExplicitlyExportInstantiatedTemplate
: public ExplicitlyExportInstantiatedTemplate
<int> {};
1606 // Base class already instantiated with import attribute.
1607 struct __declspec(dllimport
) DerivedFromExplicitlyImportInstantiatedTemplate
: public ExplicitlyImportInstantiatedTemplate
<int> {};
1609 template <typename T
> struct ExplicitInstantiationDeclTemplateBase
{ void func() {} };
1610 extern template struct ExplicitInstantiationDeclTemplateBase
<int>;
1611 struct __declspec(dllimport
) DerivedFromExplicitInstantiationDeclTemplateBase
: public ExplicitInstantiationDeclTemplateBase
<int> {};
1614 // MSVC propagates dllimport to derived classes even if they don't have external linkage.
1615 class LocalDerivedFromImportedClass
: public ImportedClass
{};
1616 class LocalDerivedFromImportedTemplate
: public ImportedClassTemplate
<int> {};
1617 #if defined(GNU) || defined(WI)
1618 // expected-note@+2{{in instantiation of template class 'ImportedClassTemplate<LocalCRTP>' requested here}}
1620 class LocalCRTP
: public ImportedClassTemplate
<LocalCRTP
> {};
1623 //===----------------------------------------------------------------------===//
1625 //===----------------------------------------------------------------------===//
1626 // The MS ABI doesn't provide a stable mangling for lambdas, so they can't be imported or exported.
1627 #if defined(MS) || defined(WI) || defined(PS)
1628 // expected-error@+4{{lambda cannot be declared 'dllimport'}}
1630 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1632 auto Lambda
= []() __declspec(dllimport
) -> bool { return true; };