Debian Codegraph @

clang/test/SemaCXX/dllimport.cpp

raw
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-pc-cygwin -fsyntax-only -fms-extensions -verify -std=c++1y -Wunsupported-dll-base-class-template -DGNU %s
7 // RUN: %clang_cc1 -triple x86_64-pc-cygwin -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DGNU %s
8 // RUN: %clang_cc1 -triple x86_64-pc-cygwin -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DGNU %s
9 // RUN: %clang_cc1 -triple i686-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++11 -Wunsupported-dll-base-class-template -DWI %s
10 // RUN: %clang_cc1 -triple x86_64-windows-itanium -fsyntax-only -fms-extensions -verify -std=c++17 -Wunsupported-dll-base-class-template -DWI %s
11 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -fdeclspec -verify -std=c++11 -Wunsupported-dll-base-class-template -DPS %s
12 // RUN: %clang_cc1 -triple x86_64-scei-ps4 -fsyntax-only -fdeclspec -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
13 // RUN: %clang_cc1 -triple x86_64-sie-ps5 -fsyntax-only -fdeclspec -verify -std=c++17 -Wunsupported-dll-base-class-template -DPS %s
14
15 // Helper structs to make templates more expressive.
16 struct ImplicitInst_Imported {};
17 struct ExplicitDecl_Imported {};
18 struct ExplicitInst_Imported {};
19 struct ExplicitSpec_Imported {};
20 struct ExplicitSpec_Def_Imported {};
21 struct ExplicitSpec_InlineDef_Imported {};
22 struct ExplicitSpec_NotImported {};
23 namespace { struct Internal {}; }
24
25
26 // Invalid usage.
27 __declspec(dllimport) typedef int typedef1;
28 // expected-warning@-1{{'dllimport' attribute only applies to functions, variables, classes, and Objective-C interfaces}}
29 typedef __declspec(dllimport) int typedef2;
30 // expected-warning@-1{{'dllimport' attribute only applies to}}
31 typedef int __declspec(dllimport) typedef3;
32 // expected-warning@-1{{'dllimport' attribute only applies to}}
33 typedef __declspec(dllimport) void (*FunTy)();
34 // expected-warning@-1{{'dllimport' attribute only applies to}}
35 enum __declspec(dllimport) Enum {};
36 // expected-warning@-1{{'dllimport' attribute only applies to}}
37 #if __has_feature(cxx_strong_enums)
38 enum class __declspec(dllimport) EnumClass {};
39 // expected-warning@-1{{'dllimport' attribute only applies to}}
40 #endif
41
42
43
44 //===----------------------------------------------------------------------===//
45 // Globals
46 //===----------------------------------------------------------------------===//
47
48 // Import declaration.
49 __declspec(dllimport) extern int ExternGlobalDecl;
50
51 // dllimport implies a declaration.
52 __declspec(dllimport) int GlobalDecl;
53 int **__attribute__((dllimport))* GlobalDeclChunkAttr;
54 int GlobalDeclAttr __attribute__((dllimport));
55
56 // Not allowed on definitions.
57 __declspec(dllimport) extern int ExternGlobalInit = 1; // expected-error{{definition of dllimport data}}
58 __declspec(dllimport) int GlobalInit1 = 1; // expected-error{{definition of dllimport data}}
59 int __declspec(dllimport) GlobalInit2 = 1; // expected-error{{definition of dllimport data}}
60
61 // Declare, then reject definition.
62 #ifdef GNU
63 // expected-note@+2{{previous attribute is here}}
64 #endif
65 __declspec(dllimport) extern int ExternGlobalDeclInit; // expected-note{{previous declaration is here}}
66 #if defined(MS) || defined(WI) || defined(PS)
67 // expected-warning@+4{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
68 #else
69 // expected-warning@+2{{'ExternGlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
70 #endif
71 int ExternGlobalDeclInit = 1;
72
73 #ifdef GNU
74 // expected-note@+2{{previous attribute is here}}
75 #endif
76 __declspec(dllimport) int GlobalDeclInit; // expected-note{{previous declaration is here}}
77 #if defined(MS) || defined(WI) || defined(PS)
78 // expected-warning@+4{{'GlobalDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
79 #else
80 // expected-warning@+2{{'GlobalDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
81 #endif
82 int GlobalDeclInit = 1;
83
84 #ifdef GNU
85 // expected-note@+2{{previous attribute is here}}
86 #endif
87 int *__attribute__((dllimport)) GlobalDeclChunkAttrInit; // expected-note{{previous declaration is here}}
88 #if defined(MS) || defined(WI) || defined(PS)
89 // expected-warning@+4{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
90 #else
91 // expected-warning@+2{{'GlobalDeclChunkAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
92 #endif
93 int *GlobalDeclChunkAttrInit = 0;
94
95 #ifdef GNU
96 // expected-note@+2{{previous attribute is here}}
97 #endif
98 int GlobalDeclAttrInit __attribute__((dllimport)); // expected-note{{previous declaration is here}}
99 #if defined(MS) || defined(WI) || defined(PS)
100 // expected-warning@+4{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
101 #else
102 // expected-warning@+2{{'GlobalDeclAttrInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
103 #endif
104 int GlobalDeclAttrInit = 1;
105
106 // Redeclarations
107 __declspec(dllimport) extern int GlobalRedecl1;
108 __declspec(dllimport) extern int GlobalRedecl1;
109
110 __declspec(dllimport) int GlobalRedecl2a;
111 __declspec(dllimport) int GlobalRedecl2a;
112
113 int *__attribute__((dllimport)) GlobalRedecl2b;
114 int *__attribute__((dllimport)) GlobalRedecl2b;
115
116 int GlobalRedecl2c __attribute__((dllimport));
117 int GlobalRedecl2c __attribute__((dllimport));
118
119 __declspec(dllimport) extern int GlobalRedecl3; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
120 extern int GlobalRedecl3; // expected-warning{{'GlobalRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
121
122 extern int GlobalRedecl4; // expected-note{{previous declaration is here}}
123 __declspec(dllimport) extern int GlobalRedecl4; // expected-warning{{redeclaration of 'GlobalRedecl4' should not add 'dllimport' attribute}}
124
125 extern "C" {
126 extern int GlobalRedecl5; // expected-note{{previous declaration is here}}
127 __declspec(dllimport) extern int GlobalRedecl5; // expected-warning{{redeclaration of 'GlobalRedecl5' should not add 'dllimport' attribute}}
128 }
129
130 // External linkage is required.
131 __declspec(dllimport) static int StaticGlobal; // expected-error{{'StaticGlobal' must have external linkage when declared 'dllimport'}}
132 __declspec(dllimport) Internal InternalTypeGlobal; // expected-error{{'InternalTypeGlobal' must have external linkage when declared 'dllimport'}}
133 #ifndef MS
134 namespace { __declspec(dllimport) int InternalGlobal; } // expected-error{{'(anonymous namespace)::InternalGlobal' must have external linkage when declared 'dllimport'}}
135 #endif
136 namespace ns { __declspec(dllimport) int ExternalGlobal; }
137
138 __declspec(dllimport) auto InternalAutoTypeGlobal = Internal(); // expected-error{{'InternalAutoTypeGlobal' must have external linkage when declared 'dllimport'}}
139 // expected-error@-1{{definition of dllimport data}}
140
141 // Thread local variables are invalid.
142 __declspec(dllimport) __thread int ThreadLocalGlobal; // expected-error{{'ThreadLocalGlobal' cannot be thread local when declared 'dllimport'}}
143 // This doesn't work on MinGW, because there, dllimport on the inline function is ignored.
144 #ifndef GNU
145 inline void __declspec(dllimport) ImportedInlineWithThreadLocal() {
146 static __thread int OK; // no-error
147 }
148 #endif
149
150 // Import in local scope.
151 __declspec(dllimport) float LocalRedecl1; // expected-note{{previous declaration is here}}
152 __declspec(dllimport) float LocalRedecl2; // expected-note{{previous declaration is here}}
153 __declspec(dllimport) float LocalRedecl3; // expected-note{{previous declaration is here}}
154 void functionScope() {
155 __declspec(dllimport) int LocalRedecl1; // expected-error{{redeclaration of 'LocalRedecl1' with a different type: 'int' vs 'float'}}
156 int *__attribute__((dllimport)) LocalRedecl2; // expected-error{{redeclaration of 'LocalRedecl2' with a different type: 'int *' vs 'float'}}
157 int LocalRedecl3 __attribute__((dllimport)); // expected-error{{redeclaration of 'LocalRedecl3' with a different type: 'int' vs 'float'}}
158
159 __declspec(dllimport) int LocalVarDecl;
160 __declspec(dllimport) int LocalVarDef = 1; // expected-error{{definition of dllimport data}}
161 __declspec(dllimport) extern int ExternLocalVarDecl;
162 __declspec(dllimport) extern int ExternLocalVarDef = 1; // expected-error{{definition of dllimport data}}
163 __declspec(dllimport) static int StaticLocalVar; // expected-error{{'StaticLocalVar' must have external linkage when declared 'dllimport'}}
164 }
165
166
167
168 //===----------------------------------------------------------------------===//
169 // Variable templates
170 //===----------------------------------------------------------------------===//
171 #if __has_feature(cxx_variable_templates)
172
173 // Import declaration.
174 template<typename T> __declspec(dllimport) extern int ExternVarTmplDecl;
175
176 // dllimport implies a declaration.
177 template<typename T> __declspec(dllimport) int VarTmplDecl;
178
179 // Not allowed on definitions.
180 template<typename T> __declspec(dllimport) extern int ExternVarTmplInit = 1; // expected-error{{definition of dllimport data}}
181 template<typename T> __declspec(dllimport) int VarTmplInit1 = 1; // expected-error{{definition of dllimport data}}
182 template<typename T> int __declspec(dllimport) VarTmplInit2 = 1; // expected-error{{definition of dllimport data}}
183
184 // Declare, then reject definition.
185 #ifdef GNU
186 // expected-note@+3{{previous attribute is here}}
187 #endif
188 template <typename T>
189 __declspec(dllimport) extern int ExternVarTmplDeclInit; // expected-note{{previous declaration is here}}
190 #if defined(MS) || defined(WI) || defined(PS)
191 // expected-warning@+5{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
192 #else
193 // expected-warning@+3{{'ExternVarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
194 #endif
195 template <typename T>
196 int ExternVarTmplDeclInit = 1;
197
198 #ifdef GNU
199 // expected-note@+3{{previous attribute is here}}
200 #endif
201 template <typename T>
202 __declspec(dllimport) int VarTmplDeclInit; // expected-note{{previous declaration is here}}
203 #if defined(MS) || defined(WI) || defined(PS)
204 // expected-warning@+5{{'VarTmplDeclInit' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
205 #else
206 // expected-warning@+3{{'VarTmplDeclInit' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
207 #endif
208 template <typename T>
209 int VarTmplDeclInit = 1;
210
211 // Redeclarations
212 template<typename T> __declspec(dllimport) extern int VarTmplRedecl1;
213 template<typename T> __declspec(dllimport) extern int VarTmplRedecl1;
214
215 template<typename T> __declspec(dllimport) int VarTmplRedecl2;
216 template<typename T> __declspec(dllimport) int VarTmplRedecl2;
217
218 template<typename T> __declspec(dllimport) extern int VarTmplRedecl3; // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
219 template<typename T> extern int VarTmplRedecl3; // expected-warning{{'VarTmplRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
220
221 template<typename T> extern int VarTmplRedecl4; // expected-note{{previous declaration is here}}
222 template<typename T> __declspec(dllimport) extern int VarTmplRedecl4; // expected-error{{redeclaration of 'VarTmplRedecl4' cannot add 'dllimport' attribute}}
223
224 // External linkage is required.
225 template<typename T> __declspec(dllimport) static int StaticVarTmpl; // expected-error{{'StaticVarTmpl' must have external linkage when declared 'dllimport'}}
226 template<typename T> __declspec(dllimport) Internal InternalTypeVarTmpl; // expected-error{{'InternalTypeVarTmpl' must have external linkage when declared 'dllimport'}}
227 #ifndef MS
228 namespace { template<typename T> __declspec(dllimport) int InternalVarTmpl; } // expected-error{{'(anonymous namespace)::InternalVarTmpl' must have external linkage when declared 'dllimport'}}
229 #endif
230 namespace ns { template<typename T> __declspec(dllimport) int ExternalVarTmpl; }
231
232 template<typename T> __declspec(dllimport) auto InternalAutoTypeVarTmpl = Internal(); // expected-error{{definition of dllimport data}} // expected-error{{'InternalAutoTypeVarTmpl' must have external linkage when declared 'dllimport'}}
233
234
235 template<typename T> int VarTmpl;
236 template<typename T> __declspec(dllimport) int ImportedVarTmpl;
237
238 // Import implicit instantiation of an imported variable template.
239 int useVarTmpl() { return ImportedVarTmpl<ImplicitInst_Imported>; }
240
241 // Import explicit instantiation declaration of an imported variable template.
242 extern template int ImportedVarTmpl<ExplicitDecl_Imported>;
243
244 // An explicit instantiation definition of an imported variable template cannot
245 // be imported because the template must be defined which is illegal.
246
247 // Import specialization of an imported variable template.
248 template<> __declspec(dllimport) int ImportedVarTmpl<ExplicitSpec_Imported>;
249 template<> __declspec(dllimport) int ImportedVarTmpl<ExplicitSpec_Def_Imported> = 1; // expected-error{{definition of dllimport data}}
250
251 // Not importing specialization of an imported variable template without
252 // explicit dllimport.
253 template<> int ImportedVarTmpl<ExplicitSpec_NotImported>;
254
255
256 // Import explicit instantiation declaration of a non-imported variable template.
257 extern template __declspec(dllimport) int VarTmpl<ExplicitDecl_Imported>;
258
259 // Import explicit instantiation definition of a non-imported variable template.
260 template __declspec(dllimport) int VarTmpl<ExplicitInst_Imported>;
261
262 // Import specialization of a non-imported variable template.
263 template<> __declspec(dllimport) int VarTmpl<ExplicitSpec_Imported>;
264 template<> __declspec(dllimport) int VarTmpl<ExplicitSpec_Def_Imported> = 1; // expected-error{{definition of dllimport data}}
265
266 #endif // __has_feature(cxx_variable_templates)
267
268
269 //===----------------------------------------------------------------------===//
270 // Functions
271 //===----------------------------------------------------------------------===//
272
273 // Import function declaration. Check different placements.
274 __attribute__((dllimport)) void decl1A(); // Validation check with __attribute__
275 __declspec(dllimport) void decl1B();
276
277 void __attribute__((dllimport)) decl2A();
278 void __declspec(dllimport) decl2B();
279
280 // Not allowed on function definitions.
281 __declspec(dllimport) void def() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
282
283 // extern "C"
284 extern "C" __declspec(dllimport) void externC();
285
286 // Import inline function.
287 #ifdef GNU
288 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
289 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
290 #endif
291 __declspec(dllimport) inline void inlineFunc1() {}
292 inline void __attribute__((dllimport)) inlineFunc2() {}
293
294 #ifdef GNU
295 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
296 #endif
297 __declspec(dllimport) inline void inlineDecl();
298 void inlineDecl() {}
299
300 __declspec(dllimport) void inlineDef();
301 #ifdef GNU
302 // expected-warning@+2{{'inlineDef' redeclared inline; 'dllimport' attribute ignored}}
303 #endif
304 inline void inlineDef() {}
305
306 // Redeclarations
307 __declspec(dllimport) void redecl1();
308 __declspec(dllimport) void redecl1();
309
310 __declspec(dllimport) void redecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
311 void redecl2(); // expected-warning{{'redecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
312
313 #ifdef GNU
314 // expected-note@+2{{previous attribute is here}}
315 #endif
316 __declspec(dllimport) void redecl3(); // expected-note{{previous declaration is here}}
317 // NB: Both MSVC and Clang issue a warning and make redecl3 dllexport.
318 #if defined(MS) || defined(WI) || defined(PS)
319 // expected-warning@+4{{'redecl3' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
320 #else
321 // expected-warning@+2{{'redecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
322 #endif
323 void redecl3() {}
324
325 void redecl4(); // expected-note{{previous declaration is here}}
326 __declspec(dllimport) void redecl4(); // expected-warning{{redeclaration of 'redecl4' should not add 'dllimport' attribute}}
327
328 extern "C" {
329 void redecl5(); // expected-note{{previous declaration is here}}
330 __declspec(dllimport) void redecl5(); // expected-warning{{redeclaration of 'redecl5' should not add 'dllimport' attribute}}
331 }
332
333 #if defined(MS) || defined(WI) || defined(PS)
334 void redecl6(); // expected-note{{previous declaration is here}}
335 __declspec(dllimport) inline void redecl6() {} // expected-warning{{redeclaration of 'redecl6' should not add 'dllimport' attribute}}
336 #else
337 void redecl6();
338 __declspec(dllimport) inline void redecl6() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
339 #endif
340
341 // Friend functions
342 struct FuncFriend {
343 friend __declspec(dllimport) void friend1();
344 friend __declspec(dllimport) void friend2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
345 #ifdef GNU
346 // expected-note@+2{{previous attribute is here}}
347 #endif
348 friend __declspec(dllimport) void friend3(); // expected-note{{previous declaration is here}}
349 friend void friend4(); // expected-note{{previous declaration is here}}
350 #if defined(MS) || defined(WI) || defined(PS)
351 // expected-note@+2{{previous declaration is here}}
352 #endif
353 friend void friend5();
354 };
355 __declspec(dllimport) void friend1();
356 void friend2(); // expected-warning{{'friend2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
357 #if defined(MS) || defined(WI) || defined(PS)
358 // expected-warning@+4{{'friend3' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
359 #else
360 // expected-warning@+2{{'friend3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
361 #endif
362 void friend3() {}
363 __declspec(dllimport) void friend4(); // expected-warning{{redeclaration of 'friend4' should not add 'dllimport' attribute}}
364 #if defined(MS) || defined(WI) || defined(PS)
365 __declspec(dllimport) inline void friend5() {} // expected-warning{{redeclaration of 'friend5' should not add 'dllimport' attribute}}
366 #else
367 __declspec(dllimport) inline void friend5() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
368 #endif
369
370
371 void __declspec(dllimport) friend6(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
372 void __declspec(dllimport) friend7();
373 struct FuncFriend2 {
374 friend void friend6(); // expected-warning{{'friend6' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
375 friend void ::friend7();
376 };
377
378 // Implicit declarations can be redeclared with dllimport.
379 __declspec(dllimport) void* operator new(__SIZE_TYPE__ n);
380
381 // External linkage is required.
382 __declspec(dllimport) static int staticFunc(); // expected-error{{'staticFunc' must have external linkage when declared 'dllimport'}}
383 __declspec(dllimport) Internal internalRetFunc(); // expected-error{{'internalRetFunc' must have external linkage when declared 'dllimport'}}
384 namespace { __declspec(dllimport) void internalFunc(); } // expected-error{{'(anonymous namespace)::internalFunc' must have external linkage when declared 'dllimport'}}
385 namespace ns { __declspec(dllimport) void externalFunc(); }
386
387 // Import deleted functions.
388 // FIXME: Deleted functions are definitions so a missing inline is diagnosed
389 // here which is irrelevant. But because the delete keyword is parsed later
390 // there is currently no straight-forward way to avoid this diagnostic.
391 __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}}
392 #if defined(MS) || defined(WI) || defined(PS)
393 __declspec(dllimport) inline void deletedInlineFunc() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
394 #else
395 __declspec(dllimport) inline void deletedInlineFunc() = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
396 #endif
397
398
399
400 //===----------------------------------------------------------------------===//
401 // Function templates
402 //===----------------------------------------------------------------------===//
403
404 // Import function template declaration. Check different placements.
405 template<typename T> __declspec(dllimport) void funcTmplDecl1();
406 template<typename T> void __declspec(dllimport) funcTmplDecl2();
407
408 // Import function template definition.
409 template<typename T> __declspec(dllimport) void funcTmplDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
410
411 // Import inline function template.
412 #ifdef GNU // MinGW always ignores dllimport on inline functions.
413
414 template<typename T> __declspec(dllimport) inline void inlineFuncTmpl1() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
415 template<typename T> inline void __attribute__((dllimport)) inlineFuncTmpl2() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
416
417 template<typename T> __declspec(dllimport) inline void inlineFuncTmplDecl(); // expected-warning{{'dllimport' attribute ignored on inline function}}
418 template<typename T> void inlineFuncTmplDecl() {}
419
420 template<typename T> __declspec(dllimport) void inlineFuncTmplDef();
421 template<typename T> inline void inlineFuncTmplDef() {} // expected-warning{{'inlineFuncTmplDef' redeclared inline; 'dllimport' attribute ignored}}
422
423 #else // MSVC drops dllimport when the function template is redeclared without it. (It doesn't warn, but we do.)
424
425 template<typename T> __declspec(dllimport) inline void inlineFuncTmpl1() {}
426 template<typename T> inline void __attribute__((dllimport)) inlineFuncTmpl2() {}
427
428 template<typename T> __declspec(dllimport) inline void inlineFuncTmplDecl(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
429 template<typename T> void inlineFuncTmplDecl() {} // expected-warning{{'inlineFuncTmplDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
430
431 template<typename T> __declspec(dllimport) void inlineFuncTmplDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
432 template<typename T> inline void inlineFuncTmplDef() {} // expected-warning{{'inlineFuncTmplDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
433 #endif
434
435 // Redeclarations
436 template<typename T> __declspec(dllimport) void funcTmplRedecl1();
437 template<typename T> __declspec(dllimport) void funcTmplRedecl1();
438
439 template<typename T> __declspec(dllimport) void funcTmplRedecl2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
440 template<typename T> void funcTmplRedecl2(); // expected-warning{{'funcTmplRedecl2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
441
442 template<typename T> __declspec(dllimport) void funcTmplRedecl3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
443 template<typename T> void funcTmplRedecl3() {} // expected-warning{{'funcTmplRedecl3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
444
445 template<typename T> void funcTmplRedecl4(); // expected-note{{previous declaration is here}}
446 template<typename T> __declspec(dllimport) void funcTmplRedecl4(); // expected-error{{redeclaration of 'funcTmplRedecl4' cannot add 'dllimport' attribute}}
447
448 #ifdef MS
449 template<typename T> void funcTmplRedecl5(); // expected-note{{previous declaration is here}}
450 template<typename T> __declspec(dllimport) inline void funcTmplRedecl5() {} // expected-error{{redeclaration of 'funcTmplRedecl5' cannot add 'dllimport' attribute}}
451 #endif
452
453 // Function template friends
454 struct FuncTmplFriend {
455 template<typename T> friend __declspec(dllimport) void funcTmplFriend1();
456 template<typename T> friend __declspec(dllimport) void funcTmplFriend2(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
457 template<typename T> friend __declspec(dllimport) void funcTmplFriend3(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
458 template<typename T> friend void funcTmplFriend4(); // expected-note{{previous declaration is here}}
459 #ifdef GNU
460 // expected-warning@+4{{'dllimport' attribute ignored on inline function}}
461 #else
462 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
463 #endif
464 template<typename T> friend __declspec(dllimport) inline void funcTmplFriend5();
465 };
466 template<typename T> __declspec(dllimport) void funcTmplFriend1();
467 template<typename T> void funcTmplFriend2(); // expected-warning{{'funcTmplFriend2' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
468 template<typename T> void funcTmplFriend3() {} // expected-warning{{'funcTmplFriend3' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
469 template<typename T> __declspec(dllimport) void funcTmplFriend4(); // expected-error{{redeclaration of 'funcTmplFriend4' cannot add 'dllimport' attribute}}
470 #if defined(MS) || defined(WI) || defined(PS)
471 // expected-warning@+2{{'funcTmplFriend5' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
472 #endif
473 template<typename T> inline void funcTmplFriend5() {}
474
475 // External linkage is required.
476 template<typename T> __declspec(dllimport) static int staticFuncTmpl(); // expected-error{{'staticFuncTmpl' must have external linkage when declared 'dllimport'}}
477 template<typename T> __declspec(dllimport) Internal internalRetFuncTmpl(); // expected-error{{'internalRetFuncTmpl' must have external linkage when declared 'dllimport'}}
478 namespace { template<typename T> __declspec(dllimport) void internalFuncTmpl(); } // expected-error{{'(anonymous namespace)::internalFuncTmpl' must have external linkage when declared 'dllimport'}}
479 namespace ns { template<typename T> __declspec(dllimport) void externalFuncTmpl(); }
480
481
482 template<typename T> void funcTmpl() {}
483 template<typename T> inline void inlineFuncTmpl() {}
484 template<typename T> __declspec(dllimport) void importedFuncTmplDecl();
485 #ifdef GNU
486 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
487 #endif
488 template<typename T> __declspec(dllimport) inline void importedFuncTmpl() {}
489
490 // Import implicit instantiation of an imported function template.
491 void useFunTmplDecl() { importedFuncTmplDecl<ImplicitInst_Imported>(); }
492 void useFunTmplDef() { importedFuncTmpl<ImplicitInst_Imported>(); }
493
494 // Import explicit instantiation declaration of an imported function template.
495 extern template void importedFuncTmpl<ExplicitDecl_Imported>();
496
497 // Import explicit instantiation definition of an imported function template.
498 // NB: MSVC fails this instantiation without explicit dllimport which is most
499 // likely a bug because an implicit instantiation is accepted.
500 template void importedFuncTmpl<ExplicitInst_Imported>();
501
502 // Import specialization of an imported function template. A definition must be
503 // declared inline.
504 template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Imported>();
505 template<> __declspec(dllimport) void importedFuncTmpl<ExplicitSpec_Def_Imported>() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
506 #ifdef MS
507 template<> __declspec(dllimport) inline void importedFuncTmpl<ExplicitSpec_InlineDef_Imported>() {}
508 #endif
509
510 // Not importing specialization of an imported function template without
511 // explicit dllimport.
512 template<> void importedFuncTmpl<ExplicitSpec_NotImported>() {}
513
514
515 // Import explicit instantiation declaration of a non-imported function template.
516 extern template __declspec(dllimport) void funcTmpl<ExplicitDecl_Imported>();
517 #ifdef GNU
518 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
519 #endif
520 extern template __declspec(dllimport) void inlineFuncTmpl<ExplicitDecl_Imported>();
521
522 // Import explicit instantiation definition of a non-imported function template.
523 template __declspec(dllimport) void funcTmpl<ExplicitInst_Imported>();
524 #ifdef GNU
525 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
526 #endif
527 template __declspec(dllimport) void inlineFuncTmpl<ExplicitInst_Imported>();
528
529 // Import specialization of a non-imported function template. A definition must
530 // be declared inline.
531 template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Imported>();
532 template<> __declspec(dllimport) void funcTmpl<ExplicitSpec_Def_Imported>() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
533 #ifdef GNU
534 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
535 #endif
536 template<> __declspec(dllimport) inline void funcTmpl<ExplicitSpec_InlineDef_Imported>() {}
537
538
539 //===----------------------------------------------------------------------===//
540 // Class members
541 //===----------------------------------------------------------------------===//
542
543 // Import individual members of a class.
544 struct ImportMembers {
545 struct Nested {
546 __declspec(dllimport) void normalDecl();
547 #ifdef GNU
548 // expected-note@+2{{previous attribute is here}}
549 #endif
550 __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}}
551 };
552
553 #ifdef GNU
554 // expected-note@+5{{previous attribute is here}}
555 // expected-warning@+5{{'dllimport' attribute ignored on inline function}}
556 // expected-warning@+6{{'dllimport' attribute ignored on inline function}}
557 #endif
558 __declspec(dllimport) void normalDecl();
559 __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}}
560 __declspec(dllimport) void normalInclass() {}
561 __declspec(dllimport) void normalInlineDef();
562 __declspec(dllimport) inline void normalInlineDecl();
563 #ifdef GNU
564 // expected-note@+5{{previous attribute is here}}
565 // expected-warning@+5{{'dllimport' attribute ignored on inline function}}
566 // expected-warning@+6{{'dllimport' attribute ignored on inline function}}
567 #endif
568 __declspec(dllimport) virtual void virtualDecl();
569 __declspec(dllimport) virtual void virtualDef(); // expected-note{{previous declaration is here}}
570 __declspec(dllimport) virtual void virtualInclass() {}
571 __declspec(dllimport) virtual void virtualInlineDef();
572 __declspec(dllimport) virtual inline void virtualInlineDecl();
573 #ifdef GNU
574 // expected-note@+5{{previous attribute is here}}
575 // expected-warning@+5{{'dllimport' attribute ignored on inline function}}
576 // expected-warning@+6{{'dllimport' attribute ignored on inline function}}
577 #endif
578 __declspec(dllimport) static void staticDecl();
579 __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}}
580 __declspec(dllimport) static void staticInclass() {}
581 __declspec(dllimport) static void staticInlineDef();
582 __declspec(dllimport) static inline void staticInlineDecl();
583
584 protected:
585 __declspec(dllimport) void protectedDecl();
586 private:
587 __declspec(dllimport) void privateDecl();
588 public:
589
590 __declspec(dllimport) int Field; // expected-warning{{'dllimport' attribute only applies to}}
591 __declspec(dllimport) static int StaticField;
592 __declspec(dllimport) static int StaticFieldDef; // expected-note{{attribute is here}}
593 __declspec(dllimport) static const int StaticConstField;
594 __declspec(dllimport) static const int StaticConstFieldDef; // expected-note{{attribute is here}}
595 __declspec(dllimport) static const int StaticConstFieldEqualInit = 1;
596 __declspec(dllimport) static const int StaticConstFieldBraceInit{1};
597 __declspec(dllimport) constexpr static int ConstexprField = 1;
598 #if __cplusplus < 201703L && !defined(MS)
599 // expected-note@+2{{attribute is here}}
600 #endif
601 __declspec(dllimport) constexpr static int ConstexprFieldDef = 1;
602 };
603
604 #if defined(MS) || defined(WI) || defined(PS)
605 // expected-warning@+4{{'ImportMembers::Nested::normalDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
606 #else
607 // expected-warning@+2{{'ImportMembers::Nested::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
608 #endif
609 void ImportMembers::Nested::normalDef() {}
610 #if defined(MS) || defined(WI) || defined(PS)
611 // expected-warning@+4{{'ImportMembers::normalDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
612 #else
613 // expected-warning@+2{{'ImportMembers::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
614 #endif
615 void ImportMembers::normalDef() {}
616 #ifdef GNU
617 // expected-warning@+2{{'ImportMembers::normalInlineDef' redeclared inline; 'dllimport' attribute ignored}}
618 #endif
619 inline void ImportMembers::normalInlineDef() {}
620 void ImportMembers::normalInlineDecl() {}
621 #if defined(MS) || defined(WI) || defined(PS)
622 // expected-warning@+4{{'ImportMembers::virtualDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
623 #else
624 // expected-warning@+2{{'ImportMembers::virtualDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
625 #endif
626 void ImportMembers::virtualDef() {}
627 #ifdef GNU
628 // expected-warning@+2{{'ImportMembers::virtualInlineDef' redeclared inline; 'dllimport' attribute ignored}}
629 #endif
630 inline void ImportMembers::virtualInlineDef() {}
631 void ImportMembers::virtualInlineDecl() {}
632 #if defined(MS) || defined(WI) || defined(PS)
633 // expected-warning@+4{{'ImportMembers::staticDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
634 #else
635 // expected-warning@+2{{'ImportMembers::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
636 #endif
637 void ImportMembers::staticDef() {}
638 #ifdef GNU
639 // expected-warning@+2{{'ImportMembers::staticInlineDef' redeclared inline; 'dllimport' attribute ignored}}
640 #endif
641 inline void ImportMembers::staticInlineDef() {}
642 void ImportMembers::staticInlineDecl() {}
643
644 int ImportMembers::StaticFieldDef; // expected-error{{definition of dllimport static field not allowed}}
645 const int ImportMembers::StaticConstFieldDef = 1; // expected-error{{definition of dllimport static field not allowed}}
646 #if __cplusplus < 201703L && !defined(MS)
647 // expected-error@+2{{definition of dllimport static field not allowed}}
648 #endif
649 constexpr int ImportMembers::ConstexprFieldDef;
650
651
652 // Import on member definitions.
653 struct ImportMemberDefs {
654 __declspec(dllimport) void normalDef();
655 __declspec(dllimport) void normalInlineDef();
656 __declspec(dllimport) virtual void virtualDef();
657 __declspec(dllimport) virtual void virtualInlineDef();
658 __declspec(dllimport) static void staticDef();
659 __declspec(dllimport) static void staticInlineDef();
660 #ifdef MS
661 __declspec(dllimport) inline void normalInlineDecl();
662 __declspec(dllimport) virtual inline void virtualInlineDecl();
663 __declspec(dllimport) static inline void staticInlineDecl();
664 #endif
665
666 __declspec(dllimport) static int StaticField;
667 __declspec(dllimport) static const int StaticConstField;
668 __declspec(dllimport) constexpr static int ConstexprField = 1;
669 };
670
671 __declspec(dllimport) void ImportMemberDefs::normalDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
672 __declspec(dllimport) void ImportMemberDefs::virtualDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
673 __declspec(dllimport) void ImportMemberDefs::staticDef() {} // expected-error{{dllimport cannot be applied to non-inline function definition}}
674 #ifdef MS
675 __declspec(dllimport) inline void ImportMemberDefs::normalInlineDef() {}
676 __declspec(dllimport) void ImportMemberDefs::normalInlineDecl() {}
677 __declspec(dllimport) inline void ImportMemberDefs::virtualInlineDef() {}
678 __declspec(dllimport) void ImportMemberDefs::virtualInlineDecl() {}
679 __declspec(dllimport) inline void ImportMemberDefs::staticInlineDef() {}
680 __declspec(dllimport) void ImportMemberDefs::staticInlineDecl() {}
681 #endif
682
683 __declspec(dllimport) int ImportMemberDefs::StaticField; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}}
684 __declspec(dllimport) const int ImportMemberDefs::StaticConstField = 1; // expected-error{{definition of dllimport static field not allowed}} expected-note{{attribute is here}}
685 #if __cplusplus < 201703L && !defined(MS)
686 // expected-error@+3{{definition of dllimport static field not allowed}}
687 // expected-note@+2{{attribute is here}}
688 #endif
689 __declspec(dllimport) constexpr int ImportMemberDefs::ConstexprField;
690
691
692 // Import special member functions.
693 struct ImportSpecials {
694 __declspec(dllimport) ImportSpecials();
695 __declspec(dllimport) ~ImportSpecials();
696 __declspec(dllimport) ImportSpecials(const ImportSpecials&);
697 __declspec(dllimport) ImportSpecials& operator=(const ImportSpecials&);
698 __declspec(dllimport) ImportSpecials(ImportSpecials&&);
699 __declspec(dllimport) ImportSpecials& operator=(ImportSpecials&&);
700 };
701
702
703 // Import deleted member functions.
704 struct ImportDeleted {
705 #if defined(MS) || defined(WI) || defined(PS)
706 __declspec(dllimport) ImportDeleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
707 __declspec(dllimport) ~ImportDeleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
708 __declspec(dllimport) ImportDeleted(const ImportDeleted&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
709 __declspec(dllimport) ImportDeleted& operator=(const ImportDeleted&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
710 __declspec(dllimport) ImportDeleted(ImportDeleted&&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
711 __declspec(dllimport) ImportDeleted& operator=(ImportDeleted&&) = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
712 __declspec(dllimport) void deleted() = delete; // expected-error{{attribute 'dllimport' cannot be applied to a deleted function}}
713 #else
714 __declspec(dllimport) ImportDeleted() = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
715 __declspec(dllimport) ~ImportDeleted() = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
716 __declspec(dllimport) ImportDeleted(const ImportDeleted&) = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
717 __declspec(dllimport) ImportDeleted& operator=(const ImportDeleted&) = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
718 __declspec(dllimport) ImportDeleted(ImportDeleted&&) = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
719 __declspec(dllimport) ImportDeleted& operator=(ImportDeleted&&) = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
720 __declspec(dllimport) void deleted() = delete; // expected-warning{{'dllimport' attribute ignored on inline function}}
721 #endif
722 };
723
724
725 // Import allocation functions.
726 struct ImportAlloc {
727 __declspec(dllimport) void* operator new(__SIZE_TYPE__);
728 __declspec(dllimport) void* operator new[](__SIZE_TYPE__);
729 __declspec(dllimport) void operator delete(void*);
730 __declspec(dllimport) void operator delete[](void*);
731 };
732
733
734 // Import defaulted member functions.
735 struct ImportDefaulted {
736 #ifdef GNU
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}}
740 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
741 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
742 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
743 #endif
744 __declspec(dllimport) ImportDefaulted() = default;
745 __declspec(dllimport) ~ImportDefaulted() = default;
746 __declspec(dllimport) ImportDefaulted(const ImportDefaulted&) = default;
747 __declspec(dllimport) ImportDefaulted& operator=(const ImportDefaulted&) = default;
748 __declspec(dllimport) ImportDefaulted(ImportDefaulted&&) = default;
749 __declspec(dllimport) ImportDefaulted& operator=(ImportDefaulted&&) = default;
750 };
751
752
753 // Import defaulted member function definitions.
754 struct ImportDefaultedDefs {
755 __declspec(dllimport) ImportDefaultedDefs();
756 #ifdef GNU
757 // expected-note@+2{{previous attribute is here}}
758 #endif
759 __declspec(dllimport) ~ImportDefaultedDefs(); // expected-note{{previous declaration is here}}
760
761 #ifdef GNU
762 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
763 // expected-note@+2{{previous declaration is here}}
764 #endif
765 __declspec(dllimport) inline ImportDefaultedDefs(const ImportDefaultedDefs&);
766 __declspec(dllimport) ImportDefaultedDefs& operator=(const ImportDefaultedDefs&);
767
768 __declspec(dllimport) ImportDefaultedDefs(ImportDefaultedDefs&&);
769 #ifdef GNU
770 // expected-note@+2{{previous attribute is here}}
771 #endif
772 __declspec(dllimport) ImportDefaultedDefs &operator=(ImportDefaultedDefs &&); // expected-note{{previous declaration is here}}
773 };
774
775 // Not allowed on definitions.
776 __declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs() = default; // expected-error{{dllimport cannot be applied to non-inline function definition}}
777
778 #if defined(MS) || defined(WI) || defined(PS)
779 // expected-warning@+5{{'ImportDefaultedDefs::~ImportDefaultedDefs' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
780 #else
781 // expected-warning@+3{{'ImportDefaultedDefs::~ImportDefaultedDefs' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
782 #endif
783 // dllimport cannot be dropped.
784 ImportDefaultedDefs::~ImportDefaultedDefs() = default;
785
786 // Import inline declaration and definition.
787 #ifdef GNU
788 // expected-error@+3{{redeclaration of 'ImportDefaultedDefs::ImportDefaultedDefs' cannot add 'dllimport' attribute}}
789 // expected-warning@+3{{'ImportDefaultedDefs::operator=' redeclared inline; 'dllimport' attribute ignored}}
790 #endif
791 __declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs(const ImportDefaultedDefs&) = default;
792 inline ImportDefaultedDefs& ImportDefaultedDefs::operator=(const ImportDefaultedDefs&) = default;
793
794 __declspec(dllimport) ImportDefaultedDefs::ImportDefaultedDefs(ImportDefaultedDefs&&) = default; // expected-error{{dllimport cannot be applied to non-inline function definition}}
795 #if defined(MS) || defined(WI) || defined(PS)
796 // expected-warning@+4{{'ImportDefaultedDefs::operator=' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
797 #else
798 // expected-warning@+2{{'ImportDefaultedDefs::operator=' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
799 #endif
800 ImportDefaultedDefs &ImportDefaultedDefs::operator=(ImportDefaultedDefs &&) = default;
801
802 // Redeclarations cannot add dllimport.
803 struct MemberRedecl {
804 void normalDef(); // expected-note{{previous declaration is here}}
805 inline void normalInlineDecl(); // expected-note{{previous declaration is here}}
806 virtual void virtualDef(); // expected-note{{previous declaration is here}}
807 virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}}
808 static void staticDef(); // expected-note{{previous declaration is here}}
809 static inline void staticInlineDecl(); // expected-note{{previous declaration is here}}
810
811 #if defined(MS) || defined(WI) || defined(PS)
812 // expected-note@+4{{previous declaration is here}}
813 // expected-note@+4{{previous declaration is here}}
814 // expected-note@+4{{previous declaration is here}}
815 #endif
816 void normalInlineDef();
817 virtual void virtualInlineDef();
818 static void staticInlineDef();
819
820 static int StaticField; // expected-note{{previous declaration is here}}
821 static const int StaticConstField; // expected-note{{previous declaration is here}}
822 constexpr static int ConstexprField = 1; // expected-note-re{{previous {{(declaration|definition)}} is here}}
823 };
824
825 __declspec(dllimport) void MemberRedecl::normalDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalDef' cannot add 'dllimport' attribute}}
826 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
827 __declspec(dllimport) void MemberRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDecl' cannot add 'dllimport' attribute}}
828 __declspec(dllimport) void MemberRedecl::virtualDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualDef' cannot add 'dllimport' attribute}}
829 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
830 __declspec(dllimport) void MemberRedecl::virtualInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDecl' cannot add 'dllimport' attribute}}
831 __declspec(dllimport) void MemberRedecl::staticDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticDef' cannot add 'dllimport' attribute}}
832 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
833 __declspec(dllimport) void MemberRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDecl' cannot add 'dllimport' attribute}}
834
835 #if defined(MS) || defined(WI) || defined(PS)
836 __declspec(dllimport) inline void MemberRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::normalInlineDef' cannot add 'dllimport' attribute}}
837 __declspec(dllimport) inline void MemberRedecl::virtualInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::virtualInlineDef' cannot add 'dllimport' attribute}}
838 __declspec(dllimport) inline void MemberRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemberRedecl::staticInlineDef' cannot add 'dllimport' attribute}}
839 #else
840 __declspec(dllimport) inline void MemberRedecl::normalInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
841 __declspec(dllimport) inline void MemberRedecl::virtualInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
842 __declspec(dllimport) inline void MemberRedecl::staticInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
843 #endif
844
845
846
847 __declspec(dllimport) int MemberRedecl::StaticField = 1; // expected-error{{redeclaration of 'MemberRedecl::StaticField' cannot add 'dllimport' attribute}}
848 // expected-error@-1{{definition of dllimport static field not allowed}}
849 // expected-note@-2{{attribute is here}}
850 __declspec(dllimport) const int MemberRedecl::StaticConstField = 1; // expected-error{{redeclaration of 'MemberRedecl::StaticConstField' cannot add 'dllimport' attribute}}
851 // expected-error@-1{{definition of dllimport static field not allowed}}
852 // expected-note@-2{{attribute is here}}
853
854 #if __cplusplus < 201703L && !defined(MS)
855 // expected-error@+6{{redeclaration of 'MemberRedecl::ConstexprField' cannot add 'dllimport' attribute}}
856 // expected-error@+5{{definition of dllimport static field not allowed}}
857 // expected-note@+4{{attribute is here}}
858 #else
859 // expected-warning@+2{{attribute declaration must precede definition}}
860 #endif
861 __declspec(dllimport) constexpr int MemberRedecl::ConstexprField;
862
863
864
865 //===----------------------------------------------------------------------===//
866 // Class member templates
867 //===----------------------------------------------------------------------===//
868
869 struct ImportMemberTmpl {
870 template<typename T> __declspec(dllimport) void normalDecl();
871 template<typename T> __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
872 #if defined(MS) || defined(WI) || defined(PS)
873 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
874 #endif
875 template<typename T> __declspec(dllimport) void normalInlineDef();
876 template<typename T> __declspec(dllimport) static void staticDecl();
877 template<typename T> __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
878 #if defined(MS) || defined(WI) || defined(PS)
879 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
880 #endif
881 template<typename T> __declspec(dllimport) static void staticInlineDef();
882
883 #ifdef GNU
884 template<typename T> __declspec(dllimport) void normalInclass() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
885 template<typename T> __declspec(dllimport) inline void normalInlineDecl(); // expected-warning{{'dllimport' attribute ignored on inline function}}
886 template<typename T> __declspec(dllimport) static void staticInclass() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
887 template<typename T> __declspec(dllimport) static inline void staticInlineDecl(); // expected-warning{{'dllimport' attribute ignored on inline function}}
888 #else
889 template<typename T> __declspec(dllimport) void normalInclass() {}
890 template<typename T> __declspec(dllimport) inline void normalInlineDecl(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
891 template<typename T> __declspec(dllimport) static void staticInclass() {}
892 template<typename T> __declspec(dllimport) static inline void staticInlineDecl(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
893 #endif
894
895 #if __has_feature(cxx_variable_templates)
896 template<typename T> __declspec(dllimport) static int StaticField;
897 template<typename T> __declspec(dllimport) static int StaticFieldDef; // expected-note{{attribute is here}}
898 template<typename T> __declspec(dllimport) static const int StaticConstField;
899 template<typename T> __declspec(dllimport) static const int StaticConstFieldDef; // expected-note{{attribute is here}}
900 template<typename T> __declspec(dllimport) static const int StaticConstFieldEqualInit = 1;
901 template<typename T> __declspec(dllimport) static const int StaticConstFieldBraceInit{1};
902 template<typename T> __declspec(dllimport) constexpr static int ConstexprField = 1;
903 template<typename T> __declspec(dllimport) constexpr static int ConstexprFieldDef = 1;
904 #endif // __has_feature(cxx_variable_templates)
905 };
906
907 template<typename T> void ImportMemberTmpl::normalDef() {} // expected-warning{{'ImportMemberTmpl::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
908 template<typename T> void ImportMemberTmpl::staticDef() {} // expected-warning{{'ImportMemberTmpl::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
909 #ifdef GNU // dllimport was ignored above
910 template<typename T> void ImportMemberTmpl::normalInlineDecl() {}
911 template<typename T> void ImportMemberTmpl::staticInlineDecl() {}
912 #else // dllimport dropped here
913 template<typename T> void ImportMemberTmpl::normalInlineDecl() {} // expected-warning{{'ImportMemberTmpl::normalInlineDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
914 template<typename T> void ImportMemberTmpl::staticInlineDecl() {} // expected-warning{{'ImportMemberTmpl::staticInlineDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
915 #endif
916
917 #ifdef GNU
918 template<typename T> inline void ImportMemberTmpl::normalInlineDef() {} // expected-warning{{ImportMemberTmpl::normalInlineDef' redeclared inline; 'dllimport' attribute ignored}}
919 template<typename T> inline void ImportMemberTmpl::staticInlineDef() {} // expected-warning{{ImportMemberTmpl::staticInlineDef' redeclared inline; 'dllimport' attribute ignored}}
920 #else
921 template<typename T> inline void ImportMemberTmpl::normalInlineDef() {} // expected-warning{{ImportMemberTmpl::normalInlineDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
922 template<typename T> inline void ImportMemberTmpl::staticInlineDef() {} // expected-warning{{ImportMemberTmpl::staticInlineDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
923 #endif
924
925 #if __has_feature(cxx_variable_templates)
926 template<typename T> int ImportMemberTmpl::StaticFieldDef; // expected-error{{definition of dllimport static field not allowed}}
927 template<typename T> const int ImportMemberTmpl::StaticConstFieldDef = 1; // expected-error{{definition of dllimport static field not allowed}}
928 #ifdef MS
929 template<typename T> constexpr int ImportMemberTmpl::ConstexprFieldDef;
930 #endif
931 #endif // __has_feature(cxx_variable_templates)
932
933
934 // Redeclarations cannot add dllimport.
935 struct MemTmplRedecl {
936 template<typename T> void normalDef(); // expected-note{{previous declaration is here}}
937 template<typename T> inline void normalInlineDecl(); // expected-note{{previous declaration is here}}
938 template<typename T> static void staticDef(); // expected-note{{previous declaration is here}}
939 template<typename T> static inline void staticInlineDecl(); // expected-note{{previous declaration is here}}
940
941 #if defined(MS) || defined(WI) || defined(PS)
942 // expected-note@+3{{previous declaration is here}}
943 // expected-note@+3{{previous declaration is here}}
944 #endif
945 template<typename T> void normalInlineDef();
946 template<typename T> static void staticInlineDef();
947
948 #if __has_feature(cxx_variable_templates)
949 template<typename T> static int StaticField; // expected-note{{previous declaration is here}}
950 template<typename T> static const int StaticConstField; // expected-note{{previous declaration is here}}
951 #ifdef MS
952 template<typename T> constexpr static int ConstexprField = 1; // expected-note{{previous definition is here}}
953 #endif
954 #endif // __has_feature(cxx_variable_templates)
955 };
956
957 template<typename T> __declspec(dllimport) void MemTmplRedecl::normalDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalDef' cannot add 'dllimport' attribute}}
958 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
959 #if defined(MS) || defined(WI) || defined(PS)
960 template<typename T> __declspec(dllimport) inline void MemTmplRedecl::normalInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDef' cannot add 'dllimport' attribute}}
961 #else
962 template<typename T> __declspec(dllimport) inline void MemTmplRedecl::normalInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
963 #endif
964 template<typename T> __declspec(dllimport) void MemTmplRedecl::normalInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::normalInlineDecl' cannot add 'dllimport' attribute}}
965 template<typename T> __declspec(dllimport) void MemTmplRedecl::staticDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticDef' cannot add 'dllimport' attribute}}
966 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
967 #if defined(MS) || defined(WI) || defined(PS)
968 template<typename T> __declspec(dllimport) inline void MemTmplRedecl::staticInlineDef() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDef' cannot add 'dllimport' attribute}}
969 #else
970 template<typename T> __declspec(dllimport) inline void MemTmplRedecl::staticInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
971 #endif
972 template<typename T> __declspec(dllimport) void MemTmplRedecl::staticInlineDecl() {} // expected-error{{redeclaration of 'MemTmplRedecl::staticInlineDecl' cannot add 'dllimport' attribute}}
973
974 #if __has_feature(cxx_variable_templates)
975 template<typename T> __declspec(dllimport) int MemTmplRedecl::StaticField = 1; // expected-error{{redeclaration of 'MemTmplRedecl::StaticField' cannot add 'dllimport' attribute}}
976 // expected-error@-1{{definition of dllimport static field not allowed}}
977 // expected-note@-2{{attribute is here}}
978 template<typename T> __declspec(dllimport) const int MemTmplRedecl::StaticConstField = 1; // expected-error{{redeclaration of 'MemTmplRedecl::StaticConstField' cannot add 'dllimport' attribute}}
979 // expected-error@-1{{definition of dllimport static field not allowed}}
980 // expected-note@-2{{attribute is here}}
981 #ifdef MS
982 // expected-warning@+1{{attribute declaration must precede definition}}
983 template<typename T> __declspec(dllimport) constexpr int MemTmplRedecl::ConstexprField;
984 #endif
985 #endif // __has_feature(cxx_variable_templates)
986
987
988
989 struct MemFunTmpl {
990 template<typename T> void normalDef() {}
991 #ifdef GNU
992 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
993 #endif
994 template<typename T> __declspec(dllimport) void importedNormal() {}
995 template<typename T> static void staticDef() {}
996 #ifdef GNU
997 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
998 #endif
999 template<typename T> __declspec(dllimport) static void importedStatic() {}
1000 };
1001
1002 // Import implicit instantiation of an imported member function template.
1003 void useMemFunTmpl() {
1004 MemFunTmpl().importedNormal<ImplicitInst_Imported>();
1005 MemFunTmpl().importedStatic<ImplicitInst_Imported>();
1006 }
1007
1008 // Import explicit instantiation declaration of an imported member function
1009 // template.
1010 extern template void MemFunTmpl::importedNormal<ExplicitDecl_Imported>();
1011 extern template void MemFunTmpl::importedStatic<ExplicitDecl_Imported>();
1012
1013 // Import explicit instantiation definition of an imported member function
1014 // template.
1015 // NB: MSVC fails this instantiation without explicit dllimport.
1016 template void MemFunTmpl::importedNormal<ExplicitInst_Imported>();
1017 template void MemFunTmpl::importedStatic<ExplicitInst_Imported>();
1018
1019 // Import specialization of an imported member function template.
1020 template<> __declspec(dllimport) void MemFunTmpl::importedNormal<ExplicitSpec_Imported>();
1021 template<> __declspec(dllimport) void MemFunTmpl::importedNormal<ExplicitSpec_Def_Imported>() {} // error on mingw
1022 #ifdef GNU
1023 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1024 #endif
1025 template<> __declspec(dllimport) inline void MemFunTmpl::importedNormal<ExplicitSpec_InlineDef_Imported>() {}
1026 #if 1
1027 // FIXME: This should not be an error when targeting MSVC. (PR21406)
1028 // expected-error@-7{{dllimport cannot be applied to non-inline function definition}}
1029 #endif
1030
1031 template<> __declspec(dllimport) void MemFunTmpl::importedStatic<ExplicitSpec_Imported>();
1032 template<> __declspec(dllimport) void MemFunTmpl::importedStatic<ExplicitSpec_Def_Imported>() {} // error on mingw
1033 #ifdef GNU
1034 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1035 #endif
1036 template<> __declspec(dllimport) inline void MemFunTmpl::importedStatic<ExplicitSpec_InlineDef_Imported>() {}
1037 #if 1
1038 // FIXME: This should not be an error when targeting MSVC. (PR21406)
1039 // expected-error@-7{{dllimport cannot be applied to non-inline function definition}}
1040 #endif
1041
1042 // Not importing specialization of an imported member function template without
1043 // explicit dllimport.
1044 template<> void MemFunTmpl::importedNormal<ExplicitSpec_NotImported>() {}
1045 template<> void MemFunTmpl::importedStatic<ExplicitSpec_NotImported>() {}
1046
1047
1048 // Import explicit instantiation declaration of a non-imported member function
1049 // template.
1050 #ifdef GNU
1051 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
1052 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
1053 #endif
1054 extern template __declspec(dllimport) void MemFunTmpl::normalDef<ExplicitDecl_Imported>();
1055 extern template __declspec(dllimport) void MemFunTmpl::staticDef<ExplicitDecl_Imported>();
1056
1057 // Import explicit instantiation definition of a non-imported member function
1058 // template.
1059 #ifdef GNU
1060 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
1061 // expected-warning@+3{{'dllimport' attribute ignored on inline function}}
1062 #endif
1063 template __declspec(dllimport) void MemFunTmpl::normalDef<ExplicitInst_Imported>();
1064 template __declspec(dllimport) void MemFunTmpl::staticDef<ExplicitInst_Imported>();
1065
1066 // Import specialization of a non-imported member function template.
1067 template<> __declspec(dllimport) void MemFunTmpl::normalDef<ExplicitSpec_Imported>();
1068 template<> __declspec(dllimport) void MemFunTmpl::normalDef<ExplicitSpec_Def_Imported>() {} // error on mingw
1069 #ifdef GNU
1070 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1071 #endif
1072 template<> __declspec(dllimport) inline void MemFunTmpl::normalDef<ExplicitSpec_InlineDef_Imported>() {}
1073 #if 1
1074 // FIXME: This should not be an error when targeting MSVC. (PR21406)
1075 // expected-error@-7{{dllimport cannot be applied to non-inline function definition}}
1076 #endif
1077
1078 template<> __declspec(dllimport) void MemFunTmpl::staticDef<ExplicitSpec_Imported>();
1079 template<> __declspec(dllimport) void MemFunTmpl::staticDef<ExplicitSpec_Def_Imported>() {} // error on mingw
1080 #ifdef GNU
1081 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1082 #endif
1083 template<> __declspec(dllimport) inline void MemFunTmpl::staticDef<ExplicitSpec_InlineDef_Imported>() {}
1084 #if 1
1085 // FIXME: This should not be an error when targeting MSVC. (PR21406)
1086 // expected-error@-7{{dllimport cannot be applied to non-inline function definition}}
1087 #endif
1088
1089
1090
1091 #if __has_feature(cxx_variable_templates)
1092 struct MemVarTmpl {
1093 template<typename T> static const int StaticVar = 1;
1094 template<typename T> __declspec(dllimport) static const int ImportedStaticVar = 1;
1095 };
1096
1097 // Import implicit instantiation of an imported member variable template.
1098 int useMemVarTmpl() { return MemVarTmpl::ImportedStaticVar<ImplicitInst_Imported>; }
1099
1100 // Import explicit instantiation declaration of an imported member variable
1101 // template.
1102 extern template const int MemVarTmpl::ImportedStaticVar<ExplicitDecl_Imported>;
1103
1104 // An explicit instantiation definition of an imported member variable template
1105 // cannot be imported because the template must be defined which is illegal. The
1106 // in-class initializer does not count.
1107
1108 // Import specialization of an imported member variable template.
1109 template<> __declspec(dllimport) const int MemVarTmpl::ImportedStaticVar<ExplicitSpec_Imported>;
1110 template<> __declspec(dllimport) const int MemVarTmpl::ImportedStaticVar<ExplicitSpec_Def_Imported> = 1;
1111 // expected-error@-1{{definition of dllimport static field not allowed}}
1112 // expected-note@-2{{attribute is here}}
1113
1114 // Not importing specialization of a member variable template without explicit
1115 // dllimport.
1116 template<> const int MemVarTmpl::ImportedStaticVar<ExplicitSpec_NotImported>;
1117
1118
1119 // Import explicit instantiation declaration of a non-imported member variable
1120 // template.
1121 extern template __declspec(dllimport) const int MemVarTmpl::StaticVar<ExplicitDecl_Imported>;
1122
1123 // An explicit instantiation definition of a non-imported member variable template
1124 // cannot be imported because the template must be defined which is illegal. The
1125 // in-class initializer does not count.
1126
1127 // Import specialization of a non-imported member variable template.
1128 template<> __declspec(dllimport) const int MemVarTmpl::StaticVar<ExplicitSpec_Imported>;
1129 template<> __declspec(dllimport) const int MemVarTmpl::StaticVar<ExplicitSpec_Def_Imported> = 1;
1130 // expected-error@-1{{definition of dllimport static field not allowed}}
1131 // expected-note@-2{{attribute is here}}
1132
1133 #endif // __has_feature(cxx_variable_templates)
1134
1135
1136
1137 //===----------------------------------------------------------------------===//
1138 // Class template members
1139 //===----------------------------------------------------------------------===//
1140
1141 // Import individual members of a class template.
1142 template<typename T>
1143 struct ImportClassTmplMembers {
1144 #ifndef GNU
1145 // expected-note@+2{{attribute is here}}
1146 #endif
1147 __declspec(dllimport) void normalDecl();
1148 #ifdef GNU
1149 // expected-note@+2{{previous attribute is here}}
1150 #endif
1151 __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}}
1152 __declspec(dllimport) void normalInlineDef();
1153 __declspec(dllimport) virtual void virtualDecl();
1154 #ifdef GNU
1155 // expected-note@+2{{previous attribute is here}}
1156 #endif
1157 __declspec(dllimport) virtual void virtualDef(); // expected-note{{previous declaration is here}}
1158 __declspec(dllimport) virtual void virtualInlineDef();
1159 __declspec(dllimport) static void staticDecl();
1160 #ifdef GNU
1161 // expected-note@+2{{previous attribute is here}}
1162 #endif
1163 __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}}
1164 __declspec(dllimport) static void staticInlineDef();
1165
1166 #ifdef GNU
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}}
1170 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1171 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1172 // expected-warning@+7{{'dllimport' attribute ignored on inline function}}
1173 #endif
1174 __declspec(dllimport) void normalInclass() {}
1175 __declspec(dllimport) inline void normalInlineDecl();
1176 __declspec(dllimport) virtual void virtualInclass() {}
1177 __declspec(dllimport) virtual inline void virtualInlineDecl();
1178 __declspec(dllimport) static void staticInclass() {}
1179 __declspec(dllimport) static inline void staticInlineDecl();
1180
1181 protected:
1182 __declspec(dllimport) void protectedDecl();
1183 private:
1184 __declspec(dllimport) void privateDecl();
1185 public:
1186
1187 __declspec(dllimport) int Field; // expected-warning{{'dllimport' attribute only applies to}}
1188 __declspec(dllimport) static int StaticField;
1189 __declspec(dllimport) static int StaticFieldDef; // expected-note{{attribute is here}}
1190 __declspec(dllimport) static const int StaticConstField;
1191 __declspec(dllimport) static const int StaticConstFieldDef; // expected-note{{attribute is here}}
1192 __declspec(dllimport) static const int StaticConstFieldEqualInit = 1;
1193 __declspec(dllimport) static const int StaticConstFieldBraceInit{1};
1194 __declspec(dllimport) constexpr static int ConstexprField = 1;
1195 #if __cplusplus < 201703L && !defined(MS)
1196 // expected-note@+2{{attribute is here}}
1197 #endif
1198 __declspec(dllimport) constexpr static int ConstexprFieldDef = 1;
1199 };
1200
1201 // NB: MSVC is inconsistent here and disallows *InlineDef on class templates,
1202 // but allows it on classes. We allow both.
1203 #if defined(MS) || defined(WI) || defined(PS)
1204 // expected-warning@+5{{'ImportClassTmplMembers::normalDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
1205 #else
1206 // expected-warning@+3{{'ImportClassTmplMembers::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1207 #endif
1208 template <typename T>
1209 void ImportClassTmplMembers<T>::normalDef() {}
1210 #ifdef GNU
1211 // expected-warning@+2{{'ImportClassTmplMembers::normalInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1212 #endif
1213 template<typename T> inline void ImportClassTmplMembers<T>::normalInlineDef() {}
1214 template<typename T> void ImportClassTmplMembers<T>::normalInlineDecl() {}
1215 #if defined(MS) || defined(WI) || defined(PS)
1216 // expected-warning@+5{{'ImportClassTmplMembers::virtualDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
1217 #else
1218 // expected-warning@+3{{'ImportClassTmplMembers::virtualDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1219 #endif
1220 template <typename T>
1221 void ImportClassTmplMembers<T>::virtualDef() {}
1222 #ifdef GNU
1223 // expected-warning@+2{{'ImportClassTmplMembers::virtualInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1224 #endif
1225 template<typename T> inline void ImportClassTmplMembers<T>::virtualInlineDef() {}
1226 template<typename T> void ImportClassTmplMembers<T>::virtualInlineDecl() {}
1227 #if defined(MS) || defined(WI) || defined(PS)
1228 // expected-warning@+5{{'ImportClassTmplMembers::staticDef' redeclared without 'dllimport' attribute: 'dllexport' attribute added}}
1229 #else
1230 // expected-warning@+3{{'ImportClassTmplMembers::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1231 #endif
1232 template <typename T>
1233 void ImportClassTmplMembers<T>::staticDef() {}
1234 #ifdef GNU
1235 // expected-warning@+2{{'ImportClassTmplMembers::staticInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1236 #endif
1237 template<typename T> inline void ImportClassTmplMembers<T>::staticInlineDef() {}
1238 template<typename T> void ImportClassTmplMembers<T>::staticInlineDecl() {}
1239
1240 template<typename T> int ImportClassTmplMembers<T>::StaticFieldDef; // expected-warning{{definition of dllimport static field}}
1241 template<typename T> const int ImportClassTmplMembers<T>::StaticConstFieldDef = 1; // expected-warning{{definition of dllimport static field}}
1242 #if __cplusplus < 201703L && !defined(MS)
1243 // expected-warning@+2{{definition of dllimport static field}}
1244 #endif
1245 template<typename T> constexpr int ImportClassTmplMembers<T>::ConstexprFieldDef;
1246
1247
1248 // Redeclarations cannot add dllimport.
1249 template<typename T>
1250 struct CTMR /*ClassTmplMemberRedecl*/ {
1251 void normalDef(); // expected-note{{previous declaration is here}}
1252 inline void normalInlineDecl(); // expected-note{{previous declaration is here}}
1253 virtual void virtualDef(); // expected-note{{previous declaration is here}}
1254 virtual inline void virtualInlineDecl(); // expected-note{{previous declaration is here}}
1255 static void staticDef(); // expected-note{{previous declaration is here}}
1256 static inline void staticInlineDecl(); // expected-note{{previous declaration is here}}
1257
1258 #if defined(MS) || defined(WI) || defined(PS)
1259 // expected-note@+4{{previous declaration is here}}
1260 // expected-note@+4{{previous declaration is here}}
1261 // expected-note@+4{{previous declaration is here}}
1262 #endif
1263 void normalInlineDef();
1264 virtual void virtualInlineDef();
1265 static void staticInlineDef();
1266
1267 static int StaticField; // expected-note{{previous declaration is here}}
1268 static const int StaticConstField; // expected-note{{previous declaration is here}}
1269 constexpr static int ConstexprField = 1; // expected-note-re{{previous {{(declaration|definition)}} is here}}
1270 };
1271
1272 template<typename T> __declspec(dllimport) void CTMR<T>::normalDef() {} // expected-error{{redeclaration of 'CTMR::normalDef' 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>::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMR::normalInlineDecl' cannot add 'dllimport' attribute}}
1275 template<typename T> __declspec(dllimport) void CTMR<T>::virtualDef() {} // expected-error{{redeclaration of 'CTMR::virtualDef' 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>::virtualInlineDecl() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDecl' cannot add 'dllimport' attribute}}
1278 template<typename T> __declspec(dllimport) void CTMR<T>::staticDef() {} // expected-error{{redeclaration of 'CTMR::staticDef' cannot add 'dllimport' attribute}}
1279 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
1280 template<typename T> __declspec(dllimport) void CTMR<T>::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMR::staticInlineDecl' cannot add 'dllimport' attribute}}
1281
1282 #if defined(MS) || defined(WI) || defined(PS)
1283 template<typename T> __declspec(dllimport) inline void CTMR<T>::normalInlineDef() {} // expected-error{{redeclaration of 'CTMR::normalInlineDef' cannot add 'dllimport' attribute}}
1284 template<typename T> __declspec(dllimport) inline void CTMR<T>::virtualInlineDef() {} // expected-error{{redeclaration of 'CTMR::virtualInlineDef' cannot add 'dllimport' attribute}}
1285 template<typename T> __declspec(dllimport) inline void CTMR<T>::staticInlineDef() {} // expected-error{{redeclaration of 'CTMR::staticInlineDef' cannot add 'dllimport' attribute}}
1286 #else
1287 template<typename T> __declspec(dllimport) inline void CTMR<T>::normalInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1288 template<typename T> __declspec(dllimport) inline void CTMR<T>::virtualInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1289 template<typename T> __declspec(dllimport) inline void CTMR<T>::staticInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1290 #endif
1291
1292 template<typename T> __declspec(dllimport) int CTMR<T>::StaticField = 1; // expected-error{{redeclaration of 'CTMR::StaticField' cannot add 'dllimport' attribute}}
1293 // expected-warning@-1{{definition of dllimport static field}}
1294 // expected-note@-2{{attribute is here}}
1295 template<typename T> __declspec(dllimport) const int CTMR<T>::StaticConstField = 1; // expected-error{{redeclaration of 'CTMR::StaticConstField' cannot add 'dllimport' attribute}}
1296 // expected-warning@-1{{definition of dllimport static field}}
1297 // expected-note@-2{{attribute is here}}
1298
1299 #if __cplusplus < 201703L && !defined(MS)
1300 // expected-error@+6{{redeclaration of 'CTMR::ConstexprField' cannot add 'dllimport' attribute}}
1301 // expected-warning@+5{{definition of dllimport static field}}
1302 // expected-note@+4{{attribute is here}}
1303 #else
1304 // expected-warning@+2{{attribute declaration must precede definition}}
1305 #endif
1306 template<typename T> __declspec(dllimport) constexpr int CTMR<T>::ConstexprField;
1307
1308
1309 // MSVC imports explicit specialization of imported class template member
1310 // function, and errors on such definitions. MinGW does not treat them as
1311 // dllimport.
1312 template <typename> struct ClassTmpl {
1313 #if !defined(GNU)
1314 // expected-note@+2{{attribute is here}}
1315 #endif
1316 void __declspec(dllimport) importedNormal();
1317 #if !defined(GNU)
1318 // expected-note@+2{{attribute is here}}
1319 #endif
1320 static void __declspec(dllimport) importedStatic();
1321 };
1322 #if !defined(GNU)
1323 // expected-error@+2{{cannot define non-inline dllimport template specialization}}
1324 #endif
1325 template<> void ClassTmpl<int>::importedNormal() {}
1326 #if !defined(GNU)
1327 // expected-error@+2{{cannot define non-inline dllimport template specialization}}
1328 #endif
1329 template<> void ClassTmpl<int>::importedStatic() {}
1330
1331 #if !defined(GNU)
1332 // expected-error@+3{{cannot define non-inline dllimport template specialization}}
1333 // expected-error@+2{{attribute 'dllimport' cannot be applied to a deleted function}}
1334 #endif
1335 template <> void ImportClassTmplMembers<int>::normalDecl() = delete;
1336
1337
1338 //===----------------------------------------------------------------------===//
1339 // Class template member templates
1340 //===----------------------------------------------------------------------===//
1341
1342 template<typename T>
1343 struct ImportClsTmplMemTmpl {
1344 template<typename U> __declspec(dllimport) void normalDecl();
1345 template<typename U> __declspec(dllimport) void normalDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
1346 #if defined(MS) || defined(WI) || defined(PS)
1347 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
1348 #endif
1349 template<typename U> __declspec(dllimport) void normalInlineDef();
1350 template<typename U> __declspec(dllimport) static void staticDecl();
1351 template<typename U> __declspec(dllimport) static void staticDef(); // expected-note{{previous declaration is here}} expected-note{{previous attribute is here}}
1352 #if defined(MS) || defined(WI) || defined(PS)
1353 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
1354 #endif
1355 template<typename U> __declspec(dllimport) static void staticInlineDef();
1356
1357 #ifdef GNU
1358 // expected-warning@+5{{'dllimport' attribute ignored on inline function}}
1359 // expected-warning@+8{{'dllimport' attribute ignored on inline function}}
1360 // expected-warning@+8{{'dllimport' attribute ignored on inline function}}
1361 // expected-warning@+11{{'dllimport' attribute ignored on inline function}}
1362 #endif
1363 template<typename U> __declspec(dllimport) void normalInclass() {}
1364 #if defined(MS) || defined(WI) || defined(PS)
1365 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
1366 #endif
1367 template<typename U> __declspec(dllimport) inline void normalInlineDecl();
1368 template<typename U> __declspec(dllimport) static void staticInclass() {}
1369 #if defined(MS) || defined(WI) || defined(PS)
1370 // expected-note@+2{{previous declaration is here}} expected-note@+2{{previous attribute is here}}
1371 #endif
1372 template<typename U> __declspec(dllimport) static inline void staticInlineDecl();
1373
1374 #if __has_feature(cxx_variable_templates)
1375 template<typename U> __declspec(dllimport) static int StaticField;
1376 template<typename U> __declspec(dllimport) static int StaticFieldDef; // expected-note{{attribute is here}}
1377 template<typename U> __declspec(dllimport) static const int StaticConstField;
1378 template<typename U> __declspec(dllimport) static const int StaticConstFieldDef; // expected-note{{attribute is here}}
1379 template<typename U> __declspec(dllimport) static const int StaticConstFieldEqualInit = 1;
1380 template<typename U> __declspec(dllimport) static const int StaticConstFieldBraceInit{1};
1381 template<typename U> __declspec(dllimport) constexpr static int ConstexprField = 1;
1382 #ifdef MS
1383 template<typename U> __declspec(dllimport) constexpr static int ConstexprFieldDef = 1;
1384 #endif
1385 #endif // __has_feature(cxx_variable_templates)
1386 };
1387
1388 template<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::normalDef() {} // expected-warning{{'ImportClsTmplMemTmpl::normalDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1389 template<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::staticDef() {} // expected-warning{{'ImportClsTmplMemTmpl::staticDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1390 #ifdef GNU
1391 template<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::normalInlineDecl() {}
1392 template<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::staticInlineDecl() {}
1393 #else
1394 template<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::normalInlineDecl() {} // expected-warning{{'ImportClsTmplMemTmpl::normalInlineDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1395 template<typename T> template<typename U> void ImportClsTmplMemTmpl<T>::staticInlineDecl() {} // expected-warning{{'ImportClsTmplMemTmpl::staticInlineDecl' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1396 #endif
1397
1398 #ifdef GNU
1399 template<typename T> template<typename U> inline void ImportClsTmplMemTmpl<T>::normalInlineDef() {} // expected-warning{{'ImportClsTmplMemTmpl::normalInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1400 template<typename T> template<typename U> inline void ImportClsTmplMemTmpl<T>::staticInlineDef() {} // expected-warning{{'ImportClsTmplMemTmpl::staticInlineDef' redeclared inline; 'dllimport' attribute ignored}}
1401 #else
1402 template<typename T> template<typename U> inline void ImportClsTmplMemTmpl<T>::normalInlineDef() {} // expected-warning{{'ImportClsTmplMemTmpl::normalInlineDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1403 template<typename T> template<typename U> inline void ImportClsTmplMemTmpl<T>::staticInlineDef() {} // expected-warning{{'ImportClsTmplMemTmpl::staticInlineDef' redeclared without 'dllimport' attribute: previous 'dllimport' ignored}}
1404 #endif
1405
1406 #if __has_feature(cxx_variable_templates)
1407 template<typename T> template<typename U> int ImportClsTmplMemTmpl<T>::StaticFieldDef; // expected-warning{{definition of dllimport static field}}
1408 template<typename T> template<typename U> const int ImportClsTmplMemTmpl<T>::StaticConstFieldDef = 1; // expected-warning{{definition of dllimport static field}}
1409 #ifdef MS
1410 template<typename T> template<typename U> constexpr int ImportClsTmplMemTmpl<T>::ConstexprFieldDef;
1411 #endif
1412 #endif // __has_feature(cxx_variable_templates)
1413
1414
1415 // Redeclarations cannot add dllimport.
1416 template<typename T>
1417 struct CTMTR /*ClassTmplMemberTmplRedecl*/ {
1418 template<typename U> void normalDef(); // expected-note{{previous declaration is here}}
1419 template<typename U> inline void normalInlineDecl(); // expected-note{{previous declaration is here}}
1420 template<typename U> static void staticDef(); // expected-note{{previous declaration is here}}
1421 template<typename U> static inline void staticInlineDecl(); // expected-note{{previous declaration is here}}
1422
1423 #if defined(MS) || defined(WI) || defined(PS)
1424 // expected-note@+3{{previous declaration is here}}
1425 // expected-note@+3{{previous declaration is here}}
1426 #endif
1427 template<typename U> void normalInlineDef();
1428 template<typename U> static void staticInlineDef();
1429
1430 #if __has_feature(cxx_variable_templates)
1431 template<typename U> static int StaticField; // expected-note{{previous declaration is here}}
1432 template<typename U> static const int StaticConstField; // expected-note{{previous declaration is here}}
1433 #ifdef MS
1434 template<typename U> constexpr static int ConstexprField = 1; // expected-note{{previous definition is here}}
1435 #endif
1436 #endif // __has_feature(cxx_variable_templates)
1437 };
1438
1439 template<typename T> template<typename U> __declspec(dllimport) void CTMTR<T>::normalDef() {} // expected-error{{redeclaration of 'CTMTR::normalDef' 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>::normalInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDecl' cannot add 'dllimport' attribute}}
1442 template<typename T> template<typename U> __declspec(dllimport) void CTMTR<T>::staticDef() {} // expected-error{{redeclaration of 'CTMTR::staticDef' cannot add 'dllimport' attribute}}
1443 // expected-error@-1{{dllimport cannot be applied to non-inline function definition}}
1444 template<typename T> template<typename U> __declspec(dllimport) void CTMTR<T>::staticInlineDecl() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDecl' cannot add 'dllimport' attribute}}
1445
1446 #if defined(MS) || defined(WI) || defined(PS)
1447 template<typename T> template<typename U> __declspec(dllimport) inline void CTMTR<T>::normalInlineDef() {} // expected-error{{redeclaration of 'CTMTR::normalInlineDef' cannot add 'dllimport' attribute}}
1448 template<typename T> template<typename U> __declspec(dllimport) inline void CTMTR<T>::staticInlineDef() {} // expected-error{{redeclaration of 'CTMTR::staticInlineDef' cannot add 'dllimport' attribute}}
1449 #else
1450 template<typename T> template<typename U> __declspec(dllimport) inline void CTMTR<T>::normalInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1451 template<typename T> template<typename U> __declspec(dllimport) inline void CTMTR<T>::staticInlineDef() {} // expected-warning{{'dllimport' attribute ignored on inline function}}
1452 #endif
1453
1454 #if __has_feature(cxx_variable_templates)
1455 template<typename T> template<typename U> __declspec(dllimport) int CTMTR<T>::StaticField = 1; // expected-error{{redeclaration of 'CTMTR::StaticField' cannot add 'dllimport' attribute}}
1456 // expected-warning@-1{{definition of dllimport static field}}
1457 // expected-note@-2{{attribute is here}}
1458 template<typename T> template<typename U> __declspec(dllimport) const int CTMTR<T>::StaticConstField = 1; // expected-error{{redeclaration of 'CTMTR::StaticConstField' cannot add 'dllimport' attribute}}
1459 // expected-warning@-1{{definition of dllimport static field}}
1460 // expected-note@-2{{attribute is here}}
1461 #ifdef MS
1462 // expected-warning@+1{{attribute declaration must precede definition}}
1463 template<typename T> template<typename U> __declspec(dllimport) constexpr int CTMTR<T>::ConstexprField;
1464 #endif
1465 #endif // __has_feature(cxx_variable_templates)
1466
1467
1468
1469 //===----------------------------------------------------------------------===//
1470 // Classes
1471 //===----------------------------------------------------------------------===//
1472
1473 namespace {
1474 struct __declspec(dllimport) AnonymousClass {}; // expected-error{{(anonymous namespace)::AnonymousClass' must have external linkage when declared 'dllimport'}}
1475 }
1476
1477 class __declspec(dllimport) ClassDecl;
1478
1479 class __declspec(dllimport) ClassDef { };
1480
1481 template <typename T> class ClassTemplate {};
1482
1483 #if defined(MS) || defined(WI) || defined(PS)
1484 // expected-note@+5{{previous attribute is here}}
1485 // expected-note@+4{{previous attribute is here}}
1486 // expected-error@+4{{attribute 'dllexport' cannot be applied to member of 'dllimport' class}}
1487 // expected-error@+4{{attribute 'dllimport' cannot be applied to member of 'dllimport' class}}
1488 #endif
1489 class __declspec(dllimport) ImportClassWithDllMember {
1490 void __declspec(dllexport) foo();
1491 void __declspec(dllimport) bar();
1492 };
1493
1494 #if defined(MS) || defined(WI) || defined(PS)
1495 // expected-note@+5{{previous attribute is here}}
1496 // expected-note@+4{{previous attribute is here}}
1497 // expected-error@+4{{attribute 'dllimport' cannot be applied to member of 'dllexport' class}}
1498 // expected-error@+4{{attribute 'dllexport' cannot be applied to member of 'dllexport' class}}
1499 #endif
1500 template <typename T> class __declspec(dllexport) ExportClassWithDllMember {
1501 void __declspec(dllimport) foo();
1502 void __declspec(dllexport) bar();
1503 };
1504
1505 namespace ImportedExplicitSpecialization {
1506 template <typename T> struct S { static int x; };
1507 template <typename T> int S<T>::x = sizeof(T);
1508 template <> struct __declspec(dllimport) S<int> { static int x; }; // expected-note{{attribute is here}}
1509 int S<int>::x = -1; // expected-error{{definition of dllimport static field not allowed}}
1510 }
1511
1512 namespace PR19988 {
1513 // Don't error about applying delete to dllimport member function when instantiating.
1514 template <typename> struct __declspec(dllimport) S {
1515 void foo() = delete;
1516 };
1517 S<int> s;
1518 }
1519
1520 #if defined(MS) || defined(WI) || defined(PS)
1521 // expected-warning@+3{{'dllimport' attribute ignored}}
1522 #endif
1523 template <typename T> struct PartiallySpecializedClassTemplate {};
1524 template <typename T> struct __declspec(dllimport) PartiallySpecializedClassTemplate<T*> { void f() {} };
1525
1526 template <typename T> struct ExpliciallySpecializedClassTemplate {};
1527 template <> struct __declspec(dllimport) ExpliciallySpecializedClassTemplate<int> { void f() {} };
1528
1529 // Function-local static constexpr in dllimport function (or class).
1530 #if defined(GNU)
1531 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1532 #endif
1533 __declspec(dllimport) inline const int *dLLImportFuncWithConstexprStatic() {
1534 static constexpr int value = 42;
1535 static constexpr const int *p = &value;
1536 static_assert(*p == 42, "");
1537 return p;
1538 }
1539 const int* (*pFunc)() = &dLLImportFuncWithConstexprStatic;
1540 bool UsedDLLImportFuncWithConstexprStatic() {
1541 return pFunc() == dLLImportFuncWithConstexprStatic();
1542 }
1543
1544 #if !defined(PS)
1545 #if defined(GNU)
1546 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1547 #endif
1548 __declspec(dllimport) __forceinline const int* dLLImportInlineFuncWithConstexprStatic() {
1549 static constexpr int value = 42;
1550 static constexpr const int* p = &value;
1551 static_assert(*p == 42, "");
1552 return p;
1553 }
1554 const int* (*pFuncForceInline)() = &dLLImportInlineFuncWithConstexprStatic;
1555 bool UsedDLLImportInlineFuncWithConstexprStatic() {
1556 return pFuncForceInline() == dLLImportInlineFuncWithConstexprStatic();
1557 }
1558 #endif // !PS
1559
1560 //===----------------------------------------------------------------------===//
1561 // Classes with template base classes
1562 //===----------------------------------------------------------------------===//
1563
1564 class __declspec(dllexport) ExportedClass {};
1565 class __declspec(dllimport) ImportedClass {};
1566
1567 template <typename T> class __declspec(dllexport) ExportedClassTemplate {};
1568
1569 #if !defined(MS) && !defined(PS)
1570 // expected-error@+2{{'ImportedClassTemplate<LocalCRTP>' must have external linkage when declared 'dllimport'}}
1571 #endif
1572 template <typename T> class __declspec(dllimport) ImportedClassTemplate {};
1573
1574 // ClassTemplate<int> gets imported.
1575 class __declspec(dllimport) DerivedFromTemplate : public ClassTemplate<int> {};
1576
1577 // ClassTemplate<int> is already imported.
1578 class __declspec(dllimport) DerivedFromTemplate2 : public ClassTemplate<int> {};
1579
1580 // ImportedClassTemplate is expliitly imported.
1581 class __declspec(dllimport) DerivedFromImportedTemplate : public ImportedClassTemplate<int> {};
1582
1583 // ExportedClassTemplate is explicitly exported.
1584 class __declspec(dllimport) DerivedFromExportedTemplate : public ExportedClassTemplate<int> {};
1585
1586 class DerivedFromTemplateD : public ClassTemplate<double> {};
1587 // Base class previously implicitly instantiated without attribute; it will get propagated.
1588 class __declspec(dllimport) DerivedFromTemplateD2 : public ClassTemplate<double> {};
1589
1590 // Base class has explicit instantiation declaration; the attribute will get propagated.
1591 extern template class ClassTemplate<float>;
1592 class __declspec(dllimport) DerivedFromTemplateF : public ClassTemplate<float> {};
1593
1594 class __declspec(dllimport) DerivedFromTemplateB : public ClassTemplate<bool> {};
1595 // The second derived class doesn't change anything, the attribute that was propagated first wins.
1596 class __declspec(dllexport) DerivedFromTemplateB2 : public ClassTemplate<bool> {};
1597
1598 template <typename T> struct ExplicitlySpecializedTemplate { void func() {} };
1599 #if defined(MS) || defined(PS)
1600 // expected-note@+2{{class template 'ExplicitlySpecializedTemplate<int>' was explicitly specialized here}}
1601 #endif
1602 template <> struct ExplicitlySpecializedTemplate<int> { void func() {} };
1603 template <typename T> struct ExplicitlyExportSpecializedTemplate { void func() {} };
1604 template <> struct __declspec(dllexport) ExplicitlyExportSpecializedTemplate<int> { void func() {} };
1605 template <typename T> struct ExplicitlyImportSpecializedTemplate { void func() {} };
1606 template <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate<int> { void func() {} };
1607
1608 template <typename T> struct ExplicitlyInstantiatedTemplate { void func() {} };
1609 #if defined(MS) || defined(PS)
1610 // expected-note@+2{{class template 'ExplicitlyInstantiatedTemplate<int>' was instantiated here}}
1611 #endif
1612 template struct ExplicitlyInstantiatedTemplate<int>;
1613 template <typename T> struct ExplicitlyExportInstantiatedTemplate { void func() {} };
1614 template struct __declspec(dllexport) ExplicitlyExportInstantiatedTemplate<int>;
1615 template <typename T> struct ExplicitlyImportInstantiatedTemplate { void func() {} };
1616 template struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate<int>;
1617
1618 #if defined(MS) || defined(PS)
1619 // expected-warning@+3{{propagating dll attribute to explicitly specialized base class template without dll attribute is not supported}}
1620 // expected-note@+2{{attribute is here}}
1621 #endif
1622 struct __declspec(dllimport) DerivedFromExplicitlySpecializedTemplate : public ExplicitlySpecializedTemplate<int> {};
1623
1624 // Base class already specialized with export attribute.
1625 struct __declspec(dllimport) DerivedFromExplicitlyExportSpecializedTemplate : public ExplicitlyExportSpecializedTemplate<int> {};
1626
1627 // Base class already specialized with import attribute.
1628 struct __declspec(dllimport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate<int> {};
1629
1630 #if defined(MS) || defined(PS)
1631 // expected-warning@+3{{propagating dll attribute to already instantiated base class template without dll attribute is not supported}}
1632 // expected-note@+2{{attribute is here}}
1633 #endif
1634 struct __declspec(dllimport) DerivedFromExplicitlyInstantiatedTemplate : public ExplicitlyInstantiatedTemplate<int> {};
1635
1636 // Base class already instantiated with export attribute.
1637 struct __declspec(dllimport) DerivedFromExplicitlyExportInstantiatedTemplate : public ExplicitlyExportInstantiatedTemplate<int> {};
1638
1639 // Base class already instantiated with import attribute.
1640 struct __declspec(dllimport) DerivedFromExplicitlyImportInstantiatedTemplate : public ExplicitlyImportInstantiatedTemplate<int> {};
1641
1642 template <typename T> struct ExplicitInstantiationDeclTemplateBase { void func() {} };
1643 extern template struct ExplicitInstantiationDeclTemplateBase<int>;
1644 struct __declspec(dllimport) DerivedFromExplicitInstantiationDeclTemplateBase : public ExplicitInstantiationDeclTemplateBase<int> {};
1645
1646 void func() {
1647 // MSVC propagates dllimport to derived classes even if they don't have external linkage.
1648 class LocalDerivedFromImportedClass : public ImportedClass {};
1649 class LocalDerivedFromImportedTemplate : public ImportedClassTemplate<int> {};
1650 #if defined(GNU) || defined(WI)
1651 // expected-note@+2{{in instantiation of template class 'ImportedClassTemplate<LocalCRTP>' requested here}}
1652 #endif
1653 class LocalCRTP : public ImportedClassTemplate<LocalCRTP> {};
1654 }
1655
1656 //===----------------------------------------------------------------------===//
1657 // Lambdas
1658 //===----------------------------------------------------------------------===//
1659 // The MS ABI doesn't provide a stable mangling for lambdas, so they can't be imported or exported.
1660 #if defined(MS) || defined(WI) || defined(PS)
1661 // expected-error@+4{{lambda cannot be declared 'dllimport'}}
1662 #else
1663 // expected-warning@+2{{'dllimport' attribute ignored on inline function}}
1664 #endif
1665 auto Lambda = []() __declspec(dllimport) -> bool { return true; };