Clang Project

clang_source_code/test/CodeGenCXX/dllexport.cpp
1// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-passes -o - %s -w -fms-compatibility-version=19.00 | FileCheck -allow-deprecated-dag-overlap --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2015 -check-prefix=M32MSVC2015 %s
2// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-passes -o - %s -w -fms-compatibility-version=18.00 | FileCheck -allow-deprecated-dag-overlap --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2013 -check-prefix=M32MSVC2013 %s
3
4// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=19.00 | FileCheck -allow-deprecated-dag-overlap --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2015 -check-prefix=M64MSVC2015 %s
5// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=18.00 | FileCheck -allow-deprecated-dag-overlap --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2013 -check-prefix=M64MSVC2013 %s
6
7// RUN: %clang_cc1 -triple i686-windows-gnu    -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck -allow-deprecated-dag-overlap --check-prefix=GNU --check-prefix=G32 %s
8// RUN: %clang_cc1 -triple x86_64-windows-gnu  -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck -allow-deprecated-dag-overlap --check-prefix=GNU --check-prefix=G64 %s
9
10// Helper structs to make templates more expressive.
11struct ImplicitInst_Exported {};
12struct ExplicitDecl_Exported {};
13struct ExplicitInst_Exported {};
14struct ExplicitSpec_Exported {};
15struct ExplicitSpec_Def_Exported {};
16struct ExplicitSpec_InlineDef_Exported {};
17struct ExplicitSpec_NotExported {};
18struct External { int v; };
19
20#define JOIN2(x, y) x##y
21#define JOIN(x, y) JOIN2(x, y)
22#define UNIQ(name) JOIN(name, __LINE__)
23#define USEVAR(var) int UNIQ(use)() { return var; }
24#define USE(func) void UNIQ(use)() { func(); }
25#define USEMEMFUNC(class, func) void (class::*UNIQ(use)())() { return &class::func; }
26#define INSTVAR(var) template int var;
27#define INST(func) template void func();
28
29// The vftable for struct W is comdat largest because we have RTTI.
30// M32-DAG: $"??_7W@@6B@" = comdat largest
31
32// M32-DAG: $"?smember@?$Base@H@PR32992@@0HA" = comdat any
33
34
35//===----------------------------------------------------------------------===//
36// Globals
37//===----------------------------------------------------------------------===//
38
39// Declarations are not exported.
40// MSC-NOT: @"?ExternGlobalDecl@@3HA"
41// GNU-NOT: @ExternGlobalDecl
42__declspec(dllexport) extern int ExternGlobalDecl;
43
44// M64-DAG: @__ImageBase = external dso_local constant i8
45
46// GNU-DAG: @_ZTVN10__cxxabiv117__class_type_infoE = external global
47
48// dllexport implies a definition.
49// MSC-DAG: @"?GlobalDef@@3HA" = dso_local dllexport global i32 0, align 4
50// GNU-DAG: @GlobalDef            = dso_local dllexport global i32 0, align 4
51__declspec(dllexport) int GlobalDef;
52
53// Export definition.
54// MSC-DAG: @"?GlobalInit1@@3HA" = dso_local dllexport global i32 1, align 4
55// GNU-DAG: @GlobalInit1            = dso_local dllexport global i32 1, align 4
56__declspec(dllexport) int GlobalInit1 = 1;
57
58// MSC-DAG: @"?GlobalInit2@@3HA" = dso_local dllexport global i32 1, align 4
59// GNU-DAG: @GlobalInit2            = dso_local dllexport global i32 1, align 4
60int __declspec(dllexport) GlobalInit2 = 1;
61
62// Declare, then export definition.
63// MSC-DAG: @"?GlobalDeclInit@@3HA" = dso_local dllexport global i32 1, align 4
64// GNU-DAG: @GlobalDeclInit            = dso_local dllexport global i32 1, align 4
65__declspec(dllexport) extern int GlobalDeclInit;
66int GlobalDeclInit = 1;
67
68// Redeclarations
69// MSC-DAG: @"?GlobalRedecl1@@3HA" = dso_local dllexport global i32 0, align 4
70// GNU-DAG: @GlobalRedecl1            = dso_local dllexport global i32 0, align 4
71__declspec(dllexport) extern int GlobalRedecl1;
72__declspec(dllexport)        int GlobalRedecl1;
73
74// MSC-DAG: @"?GlobalRedecl2@@3HA" = dso_local dllexport global i32 0, align 4
75// GNU-DAG: @GlobalRedecl2            = dso_local dllexport global i32 0, align 4
76__declspec(dllexport) extern int GlobalRedecl2;
77                             int GlobalRedecl2;
78
79// MSC-DAG: @"?ExternalGlobal@ns@@3HA" = dso_local dllexport global i32 0, align 4
80// GNU-DAG: @_ZN2ns14ExternalGlobalE      = dso_local dllexport global i32 0, align 4
81namespace ns { __declspec(dllexport) int ExternalGlobal; }
82
83// MSC-DAG: @"?ExternalAutoTypeGlobal@@3UExternal@@A" = dso_local dllexport global %struct.External zeroinitializer, align 4
84// GNU-DAG: @ExternalAutoTypeGlobal                      = dso_local dllexport global %struct.External zeroinitializer, align 4
85__declspec(dllexport) auto ExternalAutoTypeGlobal = External();
86
87int f();
88// MSC-DAG: @"?x@?1??nonInlineStaticLocalsFunc@@YAHXZ@4HA" = internal {{(unnamed_addr )*}}global i32 0
89// MSC-DAG: @"?$S1@?1??nonInlineStaticLocalsFunc@@YAHXZ@4IA" = internal {{(unnamed_addr )*}}global i32 0
90int __declspec(dllexport) nonInlineStaticLocalsFunc() {
91  static int x = f();
92  return x++;
93};
94
95// MSC-DAG: @"?x@?1??inlineStaticLocalsFunc@@YAHXZ@4HA" = weak_odr dso_local dllexport global i32 0, comdat
96// MSC-DAG: @"??_B?1??inlineStaticLocalsFunc@@YAHXZ@51" = weak_odr dllexport global i32 0, comdat
97// Note: MinGW doesn't seem to export the static local here.
98inline int __declspec(dllexport) inlineStaticLocalsFunc() {
99  static int x = f();
100  return x++;
101}
102
103namespace PR32992 {
104// Static data members of a instantiated base class should be exported.
105template <class T>
106class Base {
107  virtual void myfunc() {}
108  static int smember;
109};
110// MSC-DAG: @"?smember@?$Base@H@PR32992@@0HA" = weak_odr dso_local dllexport global i32 77, comdat, align 4
111template <class T> int Base<T>::smember = 77;
112template <class T>
113class __declspec(dllexport) Derived2 : Base<T> {
114  void myfunc() {}
115};
116class Derived : public Derived2<int> {
117  void myfunc() {}
118};
119}  // namespace PR32992
120
121namespace PR32992_1 {
122namespace a { enum b { c }; }
123template <typename> class d {
124   static constexpr a::b e = a::c;
125};
126namespace f {
127  template <typename g = int> class h : d<g> {};
128}
129using f::h;
130class __declspec(dllexport) i : h<> {};
131}
132
133//===----------------------------------------------------------------------===//
134// Variable templates
135//===----------------------------------------------------------------------===//
136
137// Declarations are not exported.
138
139// MSC-DAG: @"??$VarTmplImplicitDef@UImplicitInst_Exported@@@@3HA" = external dso_local global
140// GNU-DAG: @_Z18VarTmplImplicitDefI21ImplicitInst_ExportedE          = external global
141template<typename T> __declspec(dllexport) extern int VarTmplImplicitDef;
142USEVAR(VarTmplImplicitDef<ImplicitInst_Exported>)
143
144// Export definition.
145// MSC-DAG: @"??$VarTmplInit1@UExplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
146// GNU-DAG: @_Z12VarTmplInit1I21ExplicitInst_ExportedE          = weak_odr dso_local dllexport global i32 1, comdat, align 4
147template<typename T> __declspec(dllexport) int VarTmplInit1 = 1;
148INSTVAR(VarTmplInit1<ExplicitInst_Exported>)
149
150// MSC-DAG: @"??$VarTmplInit2@UExplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
151// GNU-DAG: @_Z12VarTmplInit2I21ExplicitInst_ExportedE          = weak_odr dso_local dllexport global i32 1, comdat, align 4
152template<typename T> int __declspec(dllexport) VarTmplInit2 = 1;
153INSTVAR(VarTmplInit2<ExplicitInst_Exported>)
154
155// Declare, then export definition.
156// MSC-DAG: @"??$VarTmplDeclInit@UExplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
157// GNU-DAG: @_Z15VarTmplDeclInitI21ExplicitInst_ExportedE          = weak_odr dso_local dllexport global i32 1, comdat, align 4
158template<typename T> __declspec(dllexport) extern int VarTmplDeclInit;
159template<typename T>                              int VarTmplDeclInit = 1;
160INSTVAR(VarTmplDeclInit<ExplicitInst_Exported>)
161
162// Redeclarations
163// MSC-DAG: @"??$VarTmplRedecl1@UExplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
164// GNU-DAG: @_Z14VarTmplRedecl1I21ExplicitInst_ExportedE          = weak_odr dso_local dllexport global i32 1, comdat, align 4
165template<typename T> __declspec(dllexport) extern int VarTmplRedecl1;
166template<typename T> __declspec(dllexport)        int VarTmplRedecl1 = 1;
167INSTVAR(VarTmplRedecl1<ExplicitInst_Exported>)
168
169// MSC-DAG: @"??$VarTmplRedecl2@UExplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
170// GNU-DAG: @_Z14VarTmplRedecl2I21ExplicitInst_ExportedE          = weak_odr dso_local dllexport global i32 1, comdat, align 4
171template<typename T> __declspec(dllexport) extern int VarTmplRedecl2;
172template<typename T>                              int VarTmplRedecl2 = 1;
173INSTVAR(VarTmplRedecl2<ExplicitInst_Exported>)
174
175// MSC-DAG: @"??$ExternalVarTmpl@UExplicitInst_Exported@@@ns@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
176// GNU-DAG: @_ZN2ns15ExternalVarTmplI21ExplicitInst_ExportedEE        = weak_odr dso_local dllexport global i32 1, comdat, align 4
177namespace ns { template<typename T> __declspec(dllexport) int ExternalVarTmpl = 1; }
178INSTVAR(ns::ExternalVarTmpl<ExplicitInst_Exported>)
179
180// MSC-DAG: @"??$ExternalAutoTypeVarTmpl@UExplicitInst_Exported@@@@3UExternal@@A" = weak_odr dso_local dllexport global %struct.External zeroinitializer, comdat, align 4
181// GNU-DAG: @_Z23ExternalAutoTypeVarTmplI21ExplicitInst_ExportedE                    = weak_odr dso_local dllexport global %struct.External zeroinitializer, comdat, align 4
182template<typename T> __declspec(dllexport) auto ExternalAutoTypeVarTmpl = External();
183template External ExternalAutoTypeVarTmpl<ExplicitInst_Exported>;
184
185
186template<typename T> int VarTmpl = 1;
187template<typename T> __declspec(dllexport) int ExportedVarTmpl = 1;
188
189// Export implicit instantiation of an exported variable template.
190// MSC-DAG: @"??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
191// GNU-DAG: @_Z15ExportedVarTmplI21ImplicitInst_ExportedE          = weak_odr dso_local dllexport global i32 1, comdat, align 4
192USEVAR(ExportedVarTmpl<ImplicitInst_Exported>)
193
194// Export explicit instantiation declaration of an exported variable template.
195// MSC-DAG: @"??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
196// GNU-DAG: @_Z15ExportedVarTmplI21ExplicitDecl_ExportedE          = weak_odr dso_local dllexport global i32 1, comdat, align 4
197extern template int ExportedVarTmpl<ExplicitDecl_Exported>;
198       template int ExportedVarTmpl<ExplicitDecl_Exported>;
199
200// Export explicit instantiation definition of an exported variable template.
201// MSC-DAG: @"??$ExportedVarTmpl@UImplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
202// GNU-DAG: @_Z15ExportedVarTmplI21ExplicitInst_ExportedE          = weak_odr dso_local dllexport global i32 1, comdat, align 4
203template __declspec(dllexport) int ExportedVarTmpl<ExplicitInst_Exported>;
204
205// Export specialization of an exported variable template.
206// MSC-DAG: @"??$ExportedVarTmpl@UExplicitSpec_Exported@@@@3HA" = dso_local dllexport global i32 0, align 4
207// GNU-DAG: @_Z15ExportedVarTmplI21ExplicitSpec_ExportedE          = dso_local dllexport global i32 0, align 4
208template<> __declspec(dllexport) int ExportedVarTmpl<ExplicitSpec_Exported>;
209
210// MSC-DAG: @"??$ExportedVarTmpl@UExplicitSpec_Def_Exported@@@@3HA" = dso_local dllexport global i32 1, align 4
211// GNU-DAG: @_Z15ExportedVarTmplI25ExplicitSpec_Def_ExportedE          = dso_local dllexport global i32 1, align 4
212template<> __declspec(dllexport) int ExportedVarTmpl<ExplicitSpec_Def_Exported> = 1;
213
214// Not exporting specialization of an exported variable template without
215// explicit dllexport.
216// MSC-DAG: @"??$ExportedVarTmpl@UExplicitSpec_NotExported@@@@3HA" = dso_local global i32 0, align 4
217// GNU-DAG: @_Z15ExportedVarTmplI24ExplicitSpec_NotExportedE          = dso_local global i32 0, align 4
218template<> int ExportedVarTmpl<ExplicitSpec_NotExported>;
219
220
221// Export explicit instantiation declaration of a non-exported variable template.
222// MSC-DAG: @"??$VarTmpl@UExplicitDecl_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
223// GNU-DAG: @_Z7VarTmplI21ExplicitDecl_ExportedE           = weak_odr dso_local dllexport global i32 1, comdat, align 4
224extern template __declspec(dllexport) int VarTmpl<ExplicitDecl_Exported>;
225       template __declspec(dllexport) int VarTmpl<ExplicitDecl_Exported>;
226
227// Export explicit instantiation definition of a non-exported variable template.
228// MSC-DAG: @"??$VarTmpl@UExplicitInst_Exported@@@@3HA" = weak_odr dso_local dllexport global i32 1, comdat, align 4
229// GNU-DAG: @_Z7VarTmplI21ExplicitInst_ExportedE           = weak_odr dso_local dllexport global i32 1, comdat, align 4
230template __declspec(dllexport) int VarTmpl<ExplicitInst_Exported>;
231
232// Export specialization of a non-exported variable template.
233// MSC-DAG: @"??$VarTmpl@UExplicitSpec_Exported@@@@3HA" = dso_local dllexport global i32 0, align 4
234// GNU-DAG: @_Z7VarTmplI21ExplicitSpec_ExportedE           = dso_local dllexport global i32 0, align 4
235template<> __declspec(dllexport) int VarTmpl<ExplicitSpec_Exported>;
236
237// MSC-DAG: @"??$VarTmpl@UExplicitSpec_Def_Exported@@@@3HA" = dso_local dllexport global i32 1, align 4
238// GNU-DAG: @_Z7VarTmplI25ExplicitSpec_Def_ExportedE           = dso_local dllexport global i32 1, align 4
239template<> __declspec(dllexport) int VarTmpl<ExplicitSpec_Def_Exported> = 1;
240
241
242
243//===----------------------------------------------------------------------===//
244// Functions
245//===----------------------------------------------------------------------===//
246
247// Declarations are not exported.
248
249// Export function definition.
250// MSC-DAG: define dso_local dllexport void @"?def@@YAXXZ"()
251// GNU-DAG: define dso_local dllexport void @_Z3defv()
252__declspec(dllexport) void def() {}
253
254// extern "C"
255// MSC-DAG: define dso_local dllexport void @externC()
256// GNU-DAG: define dso_local dllexport void @externC()
257extern "C" __declspec(dllexport) void externC() {}
258
259// Export inline function.
260// MSC-DAG: define weak_odr dso_local dllexport void @"?inlineFunc@@YAXXZ"()
261// GNU-DAG: define weak_odr dso_local dllexport void @_Z10inlineFuncv()
262__declspec(dllexport) inline void inlineFunc() {}
263
264// MSC-DAG: define weak_odr dso_local dllexport void @"?inlineDecl@@YAXXZ"()
265// GNU-DAG: define weak_odr dso_local dllexport void @_Z10inlineDeclv()
266__declspec(dllexport) inline void inlineDecl();
267                             void inlineDecl() {}
268
269// MSC-DAG: define weak_odr dso_local dllexport void @"?inlineDef@@YAXXZ"()
270// GNU-DAG: define weak_odr dso_local dllexport void @_Z9inlineDefv()
271__declspec(dllexport) void inlineDef();
272               inline void inlineDef() {}
273
274// Redeclarations
275// MSC-DAG: define dso_local dllexport void @"?redecl1@@YAXXZ"()
276// GNU-DAG: define dso_local dllexport void @_Z7redecl1v()
277__declspec(dllexport) void redecl1();
278__declspec(dllexport) void redecl1() {}
279
280// MSC-DAG: define dso_local dllexport void @"?redecl2@@YAXXZ"()
281// GNU-DAG: define dso_local dllexport void @_Z7redecl2v()
282__declspec(dllexport) void redecl2();
283                      void redecl2() {}
284
285// Friend functions
286// MSC-DAG: define dso_local dllexport void @"?friend1@@YAXXZ"()
287// GNU-DAG: define dso_local dllexport void @_Z7friend1v()
288// MSC-DAG: define dso_local dllexport void @"?friend2@@YAXXZ"()
289// GNU-DAG: define dso_local dllexport void @_Z7friend2v()
290struct FuncFriend {
291  friend __declspec(dllexport) void friend1();
292  friend __declspec(dllexport) void friend2();
293};
294__declspec(dllexport) void friend1() {}
295                      void friend2() {}
296
297// MSC-DAG: define dso_local dllexport void @"?func@Befriended@@SAXXZ"()
298// GNU-DAG: define dso_local dllexport void @_ZN10Befriended4funcEv()
299struct __declspec(dllexport) Befriended {
300  static void func();
301  struct Befriending {
302    friend void Befriended::func();
303  };
304};
305void Befriended::func() {}
306
307// Implicit declarations can be redeclared with dllexport.
308// MSC-DAG: define dso_local dllexport noalias i8* @"??2@{{YAPAXI|YAPEAX_K}}@Z"(
309// GNU-DAG: define dso_local dllexport noalias i8* @_Znw{{[yj]}}(
310void* alloc(__SIZE_TYPE__ n);
311__declspec(dllexport) void* operator new(__SIZE_TYPE__ n) { return alloc(n); }
312
313// MSC-DAG: define dso_local dllexport void @"?externalFunc@ns@@YAXXZ"()
314// GNU-DAG: define dso_local dllexport void @_ZN2ns12externalFuncEv()
315namespace ns { __declspec(dllexport) void externalFunc() {} }
316
317
318
319//===----------------------------------------------------------------------===//
320// Function templates
321//===----------------------------------------------------------------------===//
322
323// Export function template definition.
324// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmplDef@UExplicitInst_Exported@@@@YAXXZ"()
325// GNU-DAG: define weak_odr dso_local dllexport void @_Z11funcTmplDefI21ExplicitInst_ExportedEvv()
326template<typename T> __declspec(dllexport) void funcTmplDef() {}
327INST(funcTmplDef<ExplicitInst_Exported>)
328
329// Export inline function template.
330// MSC-DAG: define weak_odr dso_local dllexport void @"??$inlineFuncTmpl1@UExplicitInst_Exported@@@@YAXXZ"()
331// GNU-DAG: define weak_odr dso_local dllexport void @_Z15inlineFuncTmpl1I21ExplicitInst_ExportedEvv()
332template<typename T> __declspec(dllexport) inline void inlineFuncTmpl1() {}
333INST(inlineFuncTmpl1<ExplicitInst_Exported>)
334
335// MSC-DAG: define weak_odr dso_local dllexport void @"??$inlineFuncTmpl2@UExplicitInst_Exported@@@@YAXXZ"()
336// GNU-DAG: define weak_odr dso_local dllexport void @_Z15inlineFuncTmpl2I21ExplicitInst_ExportedEvv()
337template<typename T> inline void __attribute__((dllexport)) inlineFuncTmpl2() {}
338INST(inlineFuncTmpl2<ExplicitInst_Exported>)
339
340// MSC-DAG: define weak_odr dso_local dllexport void @"??$inlineFuncTmplDecl@UExplicitInst_Exported@@@@YAXXZ"()
341// GNU-DAG: define weak_odr dso_local dllexport void @_Z18inlineFuncTmplDeclI21ExplicitInst_ExportedEvv()
342template<typename T> __declspec(dllexport) inline void inlineFuncTmplDecl();
343template<typename T>                              void inlineFuncTmplDecl() {}
344INST(inlineFuncTmplDecl<ExplicitInst_Exported>)
345
346// MSC-DAG: define weak_odr dso_local dllexport void @"??$inlineFuncTmplDef@UExplicitInst_Exported@@@@YAXXZ"()
347// GNU-DAG: define weak_odr dso_local dllexport void @_Z17inlineFuncTmplDefI21ExplicitInst_ExportedEvv()
348template<typename T> __declspec(dllexport) void inlineFuncTmplDef();
349template<typename T>                inline void inlineFuncTmplDef() {}
350INST(inlineFuncTmplDef<ExplicitInst_Exported>)
351
352
353// Redeclarations
354// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmplRedecl1@UExplicitInst_Exported@@@@YAXXZ"()
355// GNU-DAG: define weak_odr dso_local dllexport void @_Z15funcTmplRedecl1I21ExplicitInst_ExportedEvv()
356template<typename T> __declspec(dllexport) void funcTmplRedecl1();
357template<typename T> __declspec(dllexport) void funcTmplRedecl1() {}
358INST(funcTmplRedecl1<ExplicitInst_Exported>)
359
360// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmplRedecl2@UExplicitInst_Exported@@@@YAXXZ"()
361// GNU-DAG: define weak_odr dso_local dllexport void @_Z15funcTmplRedecl2I21ExplicitInst_ExportedEvv()
362template<typename T> __declspec(dllexport) void funcTmplRedecl2();
363template<typename T>                       void funcTmplRedecl2() {}
364INST(funcTmplRedecl2<ExplicitInst_Exported>)
365
366// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmplRedecl3@UExplicitInst_Exported@@@@YAXXZ"()
367// GNU-DAG: define weak_odr dso_local dllexport void @_Z15funcTmplRedecl3I21ExplicitInst_ExportedEvv()
368template<typename T> __declspec(dllexport) void funcTmplRedecl3();
369template<typename T>                       void funcTmplRedecl3() {}
370INST(funcTmplRedecl3<ExplicitInst_Exported>)
371
372
373// Function template friends
374// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmplFriend1@UExplicitInst_Exported@@@@YAXXZ"()
375// GNU-DAG: define weak_odr dso_local dllexport void @_Z15funcTmplFriend1I21ExplicitInst_ExportedEvv()
376// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmplFriend2@UExplicitInst_Exported@@@@YAXXZ"()
377// GNU-DAG: define weak_odr dso_local dllexport void @_Z15funcTmplFriend2I21ExplicitInst_ExportedEvv()
378struct FuncTmplFriend {
379  template<typename T> friend __declspec(dllexport) void funcTmplFriend1();
380  template<typename T> friend __declspec(dllexport) void funcTmplFriend2();
381};
382template<typename T> __declspec(dllexport) void funcTmplFriend1() {}
383template<typename T>                       void funcTmplFriend2() {}
384INST(funcTmplFriend1<ExplicitInst_Exported>)
385INST(funcTmplFriend2<ExplicitInst_Exported>)
386
387// MSC-DAG: define weak_odr dso_local dllexport void @"??$externalFuncTmpl@UExplicitInst_Exported@@@ns@@YAXXZ"()
388// GNU-DAG: define weak_odr dso_local dllexport void @_ZN2ns16externalFuncTmplI21ExplicitInst_ExportedEEvv()
389namespace ns { template<typename T> __declspec(dllexport) void externalFuncTmpl() {} }
390INST(ns::externalFuncTmpl<ExplicitInst_Exported>)
391
392
393template<typename T> void funcTmpl() {}
394template<typename T> __declspec(dllexport) void exportedFuncTmpl() {}
395
396// Export implicit instantiation of an exported function template.
397// MSC-DAG: define weak_odr dso_local dllexport void @"??$exportedFuncTmpl@UImplicitInst_Exported@@@@YAXXZ"()
398// GNU-DAG: define weak_odr dso_local dllexport void @_Z16exportedFuncTmplI21ImplicitInst_ExportedEvv()
399USE(exportedFuncTmpl<ImplicitInst_Exported>)
400
401// Export explicit instantiation declaration of an exported function template.
402// MSC-DAG: define weak_odr dso_local dllexport void @"??$exportedFuncTmpl@UExplicitDecl_Exported@@@@YAXXZ"()
403// GNU-DAG: define weak_odr dso_local dllexport void @_Z16exportedFuncTmplI21ExplicitDecl_ExportedEvv()
404extern template void exportedFuncTmpl<ExplicitDecl_Exported>();
405       template void exportedFuncTmpl<ExplicitDecl_Exported>();
406
407// Export explicit instantiation definition of an exported function template.
408// MSC-DAG: define weak_odr dso_local dllexport void @"??$exportedFuncTmpl@UExplicitInst_Exported@@@@YAXXZ"()
409// GNU-DAG: define weak_odr dso_local dllexport void @_Z16exportedFuncTmplI21ExplicitInst_ExportedEvv()
410template void exportedFuncTmpl<ExplicitInst_Exported>();
411
412// Export specialization of an exported function template.
413// MSC-DAG: define dso_local dllexport void @"??$exportedFuncTmpl@UExplicitSpec_Def_Exported@@@@YAXXZ"()
414// GNU-DAG: define dso_local dllexport void @_Z16exportedFuncTmplI25ExplicitSpec_Def_ExportedEvv()
415template<> __declspec(dllexport) void exportedFuncTmpl<ExplicitSpec_Def_Exported>() {}
416
417// MSC-DAG: define weak_odr dso_local dllexport void @"??$exportedFuncTmpl@UExplicitSpec_InlineDef_Exported@@@@YAXXZ"()
418// GNU-DAG: define weak_odr dso_local dllexport void @_Z16exportedFuncTmplI31ExplicitSpec_InlineDef_ExportedEvv()
419template<> __declspec(dllexport) inline void exportedFuncTmpl<ExplicitSpec_InlineDef_Exported>() {}
420
421// Not exporting specialization of an exported function template without
422// explicit dllexport.
423// MSC-DAG: define dso_local void @"??$exportedFuncTmpl@UExplicitSpec_NotExported@@@@YAXXZ"()
424// GNU-DAG: define dso_local void @_Z16exportedFuncTmplI24ExplicitSpec_NotExportedEvv()
425template<> void exportedFuncTmpl<ExplicitSpec_NotExported>() {}
426
427
428// Export explicit instantiation declaration of a non-exported function template.
429// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmpl@UExplicitDecl_Exported@@@@YAXXZ"()
430// GNU-DAG: define weak_odr dso_local dllexport void @_Z8funcTmplI21ExplicitDecl_ExportedEvv()
431extern template __declspec(dllexport) void funcTmpl<ExplicitDecl_Exported>();
432       template __declspec(dllexport) void funcTmpl<ExplicitDecl_Exported>();
433
434// Export explicit instantiation definition of a non-exported function template.
435// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmpl@UExplicitInst_Exported@@@@YAXXZ"()
436// GNU-DAG: define weak_odr dso_local dllexport void @_Z8funcTmplI21ExplicitInst_ExportedEvv()
437template __declspec(dllexport) void funcTmpl<ExplicitInst_Exported>();
438
439// Export specialization of a non-exported function template.
440// MSC-DAG: define dso_local dllexport void @"??$funcTmpl@UExplicitSpec_Def_Exported@@@@YAXXZ"()
441// GNU-DAG: define dso_local dllexport void @_Z8funcTmplI25ExplicitSpec_Def_ExportedEvv()
442template<> __declspec(dllexport) void funcTmpl<ExplicitSpec_Def_Exported>() {}
443
444// MSC-DAG: define weak_odr dso_local dllexport void @"??$funcTmpl@UExplicitSpec_InlineDef_Exported@@@@YAXXZ"()
445// GNU-DAG: define weak_odr dso_local dllexport void @_Z8funcTmplI31ExplicitSpec_InlineDef_ExportedEvv()
446template<> __declspec(dllexport) inline void funcTmpl<ExplicitSpec_InlineDef_Exported>() {}
447
448
449
450//===----------------------------------------------------------------------===//
451// Precedence
452//===----------------------------------------------------------------------===//
453
454// dllexport takes precedence over the dllimport if both are specified.
455// MSC-DAG: @"?PrecedenceGlobal1A@@3HA" = dso_local dllexport global i32 0, align 4
456// MSC-DAG: @"?PrecedenceGlobal1B@@3HA" = dso_local dllexport global i32 0, align 4
457// GNU-DAG: @PrecedenceGlobal1A            = dso_local dllexport global i32 0, align 4
458// GNU-DAG: @PrecedenceGlobal1B            = dso_local dllexport global i32 0, align 4
459__attribute__((dllimport, dllexport))       int PrecedenceGlobal1A; // dllimport ignored
460__declspec(dllimport) __declspec(dllexport) int PrecedenceGlobal1B; // dllimport ignored
461
462// MSC-DAG: @"?PrecedenceGlobal2A@@3HA" = dso_local dllexport global i32 0, align 4
463// MSC-DAG: @"?PrecedenceGlobal2B@@3HA" = dso_local dllexport global i32 0, align 4
464// GNU-DAG: @PrecedenceGlobal2A            = dso_local dllexport global i32 0, align 4
465// GNU-DAG: @PrecedenceGlobal2B            = dso_local dllexport global i32 0, align 4
466__attribute__((dllexport, dllimport))       int PrecedenceGlobal2A; // dllimport ignored
467__declspec(dllexport) __declspec(dllimport) int PrecedenceGlobal2B; // dllimport ignored
468
469// MSC-DAG: @"?PrecedenceGlobalRedecl1@@3HA" = dso_local dllexport global i32 0, align 4
470// GNU-DAG: @PrecedenceGlobalRedecl1            = dso_local dllexport global i32 0, align 4
471__declspec(dllexport) extern int PrecedenceGlobalRedecl1;
472__declspec(dllimport)        int PrecedenceGlobalRedecl1 = 0;
473
474// MSC-DAG: @"?PrecedenceGlobalRedecl2@@3HA" = dso_local dllexport global i32 0, align 4
475// GNU-DAG: @PrecedenceGlobalRedecl2            = dso_local dllexport global i32 0, align 4
476__declspec(dllimport) extern int PrecedenceGlobalRedecl2;
477__declspec(dllexport)        int PrecedenceGlobalRedecl2;
478
479// MSC-DAG: @"?PrecedenceGlobalMixed1@@3HA" = dso_local dllexport global i32 0, align 4
480// GNU-DAG: @PrecedenceGlobalMixed1            = dso_local dllexport global i32 0, align 4
481__attribute__((dllexport)) extern int PrecedenceGlobalMixed1;
482__declspec(dllimport)             int PrecedenceGlobalMixed1 = 0;
483
484// MSC-DAG: @"?PrecedenceGlobalMixed2@@3HA" = dso_local dllexport global i32 0, align 4
485// GNU-DAG: @PrecedenceGlobalMixed2            = dso_local dllexport global i32 0, align 4
486__attribute__((dllimport)) extern int PrecedenceGlobalMixed2;
487__declspec(dllexport)             int PrecedenceGlobalMixed2;
488
489// MSC-DAG: define dso_local dllexport void @"?precedence1A@@YAXXZ"
490// MSC-DAG: define dso_local dllexport void @"?precedence1B@@YAXXZ"
491// GNU-DAG: define dso_local dllexport void @_Z12precedence1Av()
492// GNU-DAG: define dso_local dllexport void @_Z12precedence1Bv()
493void __attribute__((dllimport, dllexport))       precedence1A() {}
494void __declspec(dllimport) __declspec(dllexport) precedence1B() {}
495
496// MSC-DAG: define dso_local dllexport void @"?precedence2A@@YAXXZ"
497// MSC-DAG: define dso_local dllexport void @"?precedence2B@@YAXXZ"
498// GNU-DAG: define dso_local dllexport void @_Z12precedence2Av()
499// GNU-DAG: define dso_local dllexport void @_Z12precedence2Bv()
500void __attribute__((dllexport, dllimport))       precedence2A() {}
501void __declspec(dllexport) __declspec(dllimport) precedence2B() {}
502
503// MSC-DAG: define dso_local dllexport void @"?precedenceRedecl1@@YAXXZ"
504// GNU-DAG: define dso_local dllexport void @_Z17precedenceRedecl1v()
505void __declspec(dllimport) precedenceRedecl1();
506void __declspec(dllexport) precedenceRedecl1() {}
507
508// MSC-DAG: define dso_local dllexport void @"?precedenceRedecl2@@YAXXZ"
509// GNU-DAG: define dso_local dllexport void @_Z17precedenceRedecl2v()
510void __declspec(dllexport) precedenceRedecl2();
511void __declspec(dllimport) precedenceRedecl2() {}
512
513
514
515//===----------------------------------------------------------------------===//
516// Classes
517//===----------------------------------------------------------------------===//
518
519struct S {
520  void __declspec(dllexport) a() {}
521  // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?a@S@@QAEXXZ"
522
523  struct T {
524    void __declspec(dllexport) a() {}
525    // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?a@T@S@@QAEXXZ"
526  };
527};
528
529template <typename T>
530struct SomeTemplate {
531  SomeTemplate(T o = T()) : o(o) {}
532  T o;
533};
534// MSVC2015-DAG: define weak_odr dso_local dllexport {{.+}} @"??4?$SomeTemplate@H@@Q{{.+}}@$$Q{{.+}}@@Z"
535// MSVC2013-DAG: define weak_odr dso_local dllexport {{.+}} @"??4?$SomeTemplate@H@@Q{{.+}}0@A{{.+}}0@@Z"
536struct __declspec(dllexport) InheritFromTemplate : SomeTemplate<int> {};
537
538// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"??_F?$SomeTemplate@H@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
539
540namespace PR23801 {
541template <typename>
542struct S {
543  ~S() {}
544};
545struct A {
546  A(int);
547  S<int> s;
548};
549struct __declspec(dllexport) B {
550  B(A = 0) {}
551};
552
553}
554//
555// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FB@PR23801@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
556
557struct __declspec(dllexport) T {
558  // Copy assignment operator:
559  // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.T* @"??4T@@QAEAAU0@ABU0@@Z"
560
561  // Explicitly defaulted copy constructur:
562  T(const T&) = default;
563  // M32MSVC2013-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.T* @"??0T@@QAE@ABU0@@Z"
564
565  void a() {}
566  // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?a@T@@QAEXXZ"
567
568  static int b;
569  // M32-DAG: @"?b@T@@2HA" = external dso_local global i32
570
571  static int c;
572  // M32-DAG: @"?c@T@@2HA" = dso_local dllexport global i32 0, align 4
573};
574
575USEVAR(T::b)
576int T::c;
577
578// Export template class with static member variable
579// MSC-DAG: @"?StaticClassVarExpTmplClass@?$TmplClass@H@@2HA" = weak_odr dso_local dllexport global i32 0, comdat, align 4
580// GNU-DAG: @_ZN9TmplClassIiE26StaticClassVarExpTmplClassE = weak_odr dso_local dllexport global i32 0, comdat, align 4
581template<typename T>
582struct __declspec(dllexport) TmplClass
583{
584  static T StaticClassVarExpTmplClass;
585};
586
587template<typename T>
588T TmplClass<T>::StaticClassVarExpTmplClass;
589
590// Export a definition of a template function.
591// MSC-DAG: define weak_odr dso_local dllexport i32 @"??$TypeFunTmpl@H@@YAHH@Z"
592// GNU-DAG: define weak_odr dso_local dllexport i32 @_Z11TypeFunTmplIiET_S0_
593template<typename T>
594T __declspec(dllexport) TypeFunTmpl(T t) { return t + t; }
595
596// Instantiate the exported template class and the exported template function.
597int useExportedTmplStaticAndFun()
598{
599  return TmplClass<int>::StaticClassVarExpTmplClass + TypeFunTmpl<int>(10);
600}
601
602template <typename T> struct __declspec(dllexport) U { void foo() {} };
603struct __declspec(dllexport) V : public U<int> { };
604// U<int>'s assignment operator is emitted.
605// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.U* @"??4?$U@H@@QAEAAU0@ABU0@@Z"
606
607struct __declspec(dllexport) W { virtual void foo(); };
608void W::foo() {}
609// Default ctor:
610// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.W* @"??0W@@QAE@XZ"
611// Copy ctor:
612// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.W* @"??0W@@QAE@ABU0@@Z"
613// vftable:
614// M32-DAG: [[W_VTABLE:@.*]] = private unnamed_addr constant { [2 x i8*] } { [2 x i8*] [i8* bitcast (%rtti.CompleteObjectLocator* @"??_R4W@@6B@" to i8*), i8* bitcast (void (%struct.W*)* @"?foo@W@@UAEXXZ" to i8*)] }, comdat($"??_7W@@6B@")
615// M32-DAG: @"??_7W@@6B@" = dllexport unnamed_addr alias i8*, getelementptr inbounds ({ [2 x i8*] }, { [2 x i8*] }* [[W_VTABLE]], i32 0, i32 0, i32 1)
616// G32-DAG: @_ZTV1W = dso_local dllexport unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1W to i8*), i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to i8*)] }
617
618struct __declspec(dllexport) X : public virtual W {};
619// vbtable:
620// M32-DAG: @"??_8X@@7B@" = weak_odr dllexport unnamed_addr constant [2 x i32] [i32 0, i32 4]
621
622struct __declspec(dllexport) Y {
623  // Move assignment operator:
624  // MSVC2015-DAG: define weak_odr dso_local dllexport {{.+}} @"??4Y@@Q{{.+}}@$$Q{{.+}}@@Z"
625  // MSVC2013-DAG: define weak_odr dso_local dllexport {{.+}} @"??4Y@@Q{{.+}}0@A{{.+}}0@@Z"
626
627  int x;
628};
629
630struct __declspec(dllexport) Z { virtual ~Z() {} };
631// The scalar deleting dtor does not get exported:
632// M32-DAG: define linkonce_odr dso_local x86_thiscallcc i8* @"??_GZ@@UAEPAXI@Z"
633
634
635// The user-defined dtor does get exported:
636// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"??1Z@@UAE@XZ"
637
638namespace UseDtorAlias {
639  struct __declspec(dllexport) A { ~A(); };
640  struct __declspec(dllexport) B : A { ~B(); };
641  A::~A() { }
642  B::~B() { }
643  // Emit a alias definition of B's constructor.
644  // M32-DAG: @"??1B@UseDtorAlias@@QAE@XZ" = dso_local dllexport unnamed_addr alias {{.*}} @"??1A@UseDtorAlias@@QAE@XZ"
645}
646
647struct __declspec(dllexport) DefaultedCtorsDtors {
648  DefaultedCtorsDtors() = default;
649  // M32MSVC2013-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.DefaultedCtorsDtors* @"??0DefaultedCtorsDtors@@QAE@XZ"
650  ~DefaultedCtorsDtors() = default;
651  // M32MSVC2013-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"??1DefaultedCtorsDtors@@QAE@XZ"
652};
653
654// Export defaulted member function definitions declared inside class.
655struct __declspec(dllexport) ExportDefaultedInclassDefs {
656  ExportDefaultedInclassDefs() = default;
657  // M32VS2013-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"??0ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
658  // M64VS2013-DAG: define weak_odr dso_local dllexport                %struct.ExportDefaultedInclassDefs* @"??0ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
659  // M32VS2015-NOT: define weak_odr dso_local dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"??0ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
660  // M64VS2015-NOT: define weak_odr dso_local dllexport                %struct.ExportDefaultedInclassDefs* @"??0ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
661
662  ~ExportDefaultedInclassDefs() = default;
663  // M32VS2013-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"??1ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* %this)
664  // M64VS2013-DAG: define weak_odr dso_local dllexport                void @"??1ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* %this)
665  // M32VS2015-NOT: define weak_odr dso_local dllexport x86_thiscallcc void @"??1ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* %this)
666  // M64VS2015-NOT: define weak_odr dso_local dllexport                void @"??1ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* %this)
667
668  ExportDefaultedInclassDefs(const ExportDefaultedInclassDefs&) = default;
669  // M32VS2013-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"??0ExportDefaultedInclassDefs@@QAE@ABU0@@Z"(%struct.ExportDefaultedInclassDefs* returned %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
670  // M64VS2013-DAG: define weak_odr dso_local dllexport                %struct.ExportDefaultedInclassDefs* @"??0ExportDefaultedInclassDefs@@QEAA@AEBU0@@Z"(%struct.ExportDefaultedInclassDefs* returned %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
671  // M32VS2015-NOT: define weak_odr dso_local dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"??0ExportDefaultedInclassDefs@@QAE@ABU0@@Z"(%struct.ExportDefaultedInclassDefs* returned %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
672  // M64VS2015-NOT: define weak_odr dso_local dllexport                %struct.ExportDefaultedInclassDefs* @"??0ExportDefaultedInclassDefs@@QEAA@AEBU0@@Z"(%struct.ExportDefaultedInclassDefs* returned %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
673
674  ExportDefaultedInclassDefs& operator=(const ExportDefaultedInclassDefs&) = default;
675  // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc dereferenceable({{[0-9]+}}) %struct.ExportDefaultedInclassDefs* @"??4ExportDefaultedInclassDefs@@QAEAAU0@ABU0@@Z"(%struct.ExportDefaultedInclassDefs* %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
676  // M64-DAG: define weak_odr dso_local dllexport                dereferenceable({{[0-9]+}}) %struct.ExportDefaultedInclassDefs* @"??4ExportDefaultedInclassDefs@@QEAAAEAU0@AEBU0@@Z"(%struct.ExportDefaultedInclassDefs* %this, %struct.ExportDefaultedInclassDefs* dereferenceable({{[0-9]+}}))
677};
678
679namespace ReferencedInlineMethodInNestedClass {
680  struct __declspec(dllexport) S {
681    void foo() {
682      t->bar();
683    }
684    struct T {
685      void bar() {}
686    };
687    T *t;
688  };
689  // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?foo@S@ReferencedInlineMethodInNestedClass@@QAEXXZ"
690  // M32-DAG: define linkonce_odr dso_local x86_thiscallcc void @"?bar@T@S@ReferencedInlineMethodInNestedClass@@QAEXXZ"
691}
692
693// MS ignores DLL attributes on partial specializations.
694template <typename T> struct PartiallySpecializedClassTemplate {};
695template <typename T> struct __declspec(dllexport) PartiallySpecializedClassTemplate<T*> { void f(); };
696template <typename T> void PartiallySpecializedClassTemplate<T*>::f() {}
697USEMEMFUNC(PartiallySpecializedClassTemplate<void*>, f);
698// M32-DAG: define linkonce_odr dso_local x86_thiscallcc void @"?f@?$PartiallySpecializedClassTemplate@PAX@@QAEXXZ"
699// G32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @_ZN33PartiallySpecializedClassTemplateIPvE1fEv
700
701// Attributes on explicit specializations are honored.
702template <typename T> struct ExplicitlySpecializedClassTemplate {};
703template <> struct __declspec(dllexport) ExplicitlySpecializedClassTemplate<void*> { void f(); };
704void ExplicitlySpecializedClassTemplate<void*>::f() {}
705USEMEMFUNC(ExplicitlySpecializedClassTemplate<void*>, f);
706// M32-DAG: define dso_local dllexport x86_thiscallcc void @"?f@?$ExplicitlySpecializedClassTemplate@PAX@@QAEXXZ"
707// G32-DAG: define dso_local dllexport x86_thiscallcc void @_ZN34ExplicitlySpecializedClassTemplateIPvE1fEv
708
709// MS inherits DLL attributes to partial specializations.
710template <typename T> struct __declspec(dllexport) PartiallySpecializedExportedClassTemplate {};
711template <typename T> struct PartiallySpecializedExportedClassTemplate<T*> { void f() {} };
712USEMEMFUNC(PartiallySpecializedExportedClassTemplate<void*>, f);
713// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$PartiallySpecializedExportedClassTemplate@PAX@@QAEXXZ"
714// G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN41PartiallySpecializedExportedClassTemplateIPvE1fEv
715
716// MS ignores DLL attributes on partial specializations; inheritance still works though.
717template <typename T> struct __declspec(dllexport) PartiallySpecializedExportedClassTemplate2 {};
718template <typename T> struct __declspec(dllimport) PartiallySpecializedExportedClassTemplate2<T*> { void f(); };
719template <typename T> void PartiallySpecializedExportedClassTemplate2<T*>::f() {}
720USEMEMFUNC(PartiallySpecializedExportedClassTemplate2<void*>, f);
721// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$PartiallySpecializedExportedClassTemplate2@PAX@@QAEXXZ"
722// G32-DAG: declare dllimport x86_thiscallcc void @_ZN42PartiallySpecializedExportedClassTemplate2IPvE1fEv
723
724// Attributes on the instantiation take precedence over attributes on the template.
725template <typename T> struct __declspec(dllimport) ExplicitlyInstantiatedWithDifferentAttr { void f() {} };
726template struct __declspec(dllexport) ExplicitlyInstantiatedWithDifferentAttr<int>;
727USEMEMFUNC(ExplicitlyInstantiatedWithDifferentAttr<int>, f);
728// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$ExplicitlyInstantiatedWithDifferentAttr@H@@QAEXXZ"
729
730// Don't create weak dllexport aliases. (PR21373)
731struct NonExportedBaseClass {
732  virtual ~NonExportedBaseClass();
733};
734NonExportedBaseClass::~NonExportedBaseClass() {}
735
736struct __declspec(dllexport) ExportedDerivedClass : NonExportedBaseClass {};
737// M32-DAG: weak_odr dso_local dllexport x86_thiscallcc void @"??1ExportedDerivedClass@@UAE@XZ"
738
739// Do not assert about generating code for constexpr functions twice during explicit instantiation (PR21718).
740template <typename T> struct ExplicitInstConstexprMembers {
741  // Copy assignment operator
742  // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc dereferenceable(1) %struct.ExplicitInstConstexprMembers* @"??4?$ExplicitInstConstexprMembers@X@@QAEAAU0@ABU0@@Z"
743
744  constexpr ExplicitInstConstexprMembers() {}
745  // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.ExplicitInstConstexprMembers* @"??0?$ExplicitInstConstexprMembers@X@@QAE@XZ"
746
747  ExplicitInstConstexprMembers(const ExplicitInstConstexprMembers&) = default;
748  // M32MSVC2013-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.ExplicitInstConstexprMembers* @"??0?$ExplicitInstConstexprMembers@X@@QAE@ABU0@@Z"
749
750  constexpr int f() const { return 42; }
751  // M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc i32 @"?f@?$ExplicitInstConstexprMembers@X@@QBEHXZ"
752};
753template struct __declspec(dllexport) ExplicitInstConstexprMembers<void>;
754
755template <typename T> struct ExplicitInstantiationDeclTemplate { void f() {} };
756extern template struct __declspec(dllexport) ExplicitInstantiationDeclTemplate<int>;
757USEMEMFUNC(ExplicitInstantiationDeclTemplate<int>, f);
758// M32-DAG: {{declare|define available_externally}} dso_local x86_thiscallcc void @"?f@?$ExplicitInstantiationDeclTemplate@H@@QAEXXZ"
759
760template <typename T> struct __declspec(dllexport) ExplicitInstantiationDeclExportedTemplate { void f() {} };
761extern template struct ExplicitInstantiationDeclExportedTemplate<int>;
762USEMEMFUNC(ExplicitInstantiationDeclExportedTemplate<int>, f);
763// M32-DAG: {{declare|define available_externally}} dso_local x86_thiscallcc void @"?f@?$ExplicitInstantiationDeclExportedTemplate@H@@QAEXXZ"
764
765template <typename T> struct ExplicitInstantiationDeclExportedDefTemplate { void f() {} ExplicitInstantiationDeclExportedDefTemplate() {} };
766extern template struct ExplicitInstantiationDeclExportedDefTemplate<int>;
767template struct __declspec(dllexport) ExplicitInstantiationDeclExportedDefTemplate<int>;
768USEMEMFUNC(ExplicitInstantiationDeclExportedDefTemplate<int>, f);
769// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$ExplicitInstantiationDeclExportedDefTemplate@H@@QAEXXZ"
770// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %struct.ExplicitInstantiationDeclExportedDefTemplate* @"??0?$ExplicitInstantiationDeclExportedDefTemplate@H@@QAE@XZ"
771// G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN44ExplicitInstantiationDeclExportedDefTemplateIiE1fEv
772
773template <typename T> struct ImplicitInstantiationExportedExplicitInstantiationDefTemplate { virtual void f() {} };
774ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int> ImplicitInstantiationExportedExplicitInstantiationDefTemplateInstance;
775template struct __declspec(dllexport) ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int>;
776USEMEMFUNC(ImplicitInstantiationExportedExplicitInstantiationDefTemplate<int>, f);
777// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$ImplicitInstantiationExportedExplicitInstantiationDefTemplate@H@@UAEXXZ"
778// G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN61ImplicitInstantiationExportedExplicitInstantiationDefTemplateIiE1fEv
779
780template <typename T> struct __declspec(dllexport) ImplicitInstantiationExplicitInstantiationDefExportedTemplate { virtual void f() {} };
781ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int> ImplicitInstantiationExplicitInstantiationDefExportedTemplateInstance;
782template struct ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int>;
783USEMEMFUNC(ImplicitInstantiationExplicitInstantiationDefExportedTemplate<int>, f);
784// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$ImplicitInstantiationExplicitInstantiationDefExportedTemplate@H@@UAEXXZ"
785// G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN61ImplicitInstantiationExplicitInstantiationDefExportedTemplateIiE1fEv
786
787template <typename T> struct __declspec(dllexport) ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate { virtual void f() {} };
788ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int> ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplateInstance;
789template struct __declspec(dllexport) ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int>;
790USEMEMFUNC(ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate<int>, f);
791// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplate@H@@UAEXXZ"
792// G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN69ImplicitInstantiationExportedExplicitInstantiationDefExportedTemplateIiE1fEv
793
794namespace { struct InternalLinkageType {}; }
795struct __declspec(dllexport) PR23308 {
796  void f(InternalLinkageType*);
797};
798void PR23308::f(InternalLinkageType*) {}
799long use(PR23308* p) { p->f(nullptr); }
800// M32-DAG: define internal x86_thiscallcc void @"?f@PR23308@@QAEXPAUInternalLinkageType@?A0x{{[^@]*}}@@@Z"
801
802template <typename T> struct PR23770BaseTemplate { void f() {} };
803template <typename T> struct PR23770DerivedTemplate : PR23770BaseTemplate<int> {};
804extern template struct PR23770DerivedTemplate<int>;
805template struct __declspec(dllexport) PR23770DerivedTemplate<int>;
806// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$PR23770BaseTemplate@H@@QAEXXZ"
807
808namespace InClassInits {
809
810struct __declspec(dllexport) S {
811  int x = 42;
812};
813// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::S"* @"??0S@InClassInits@@QAE@XZ"
814
815// dllexport an already instantiated class template.
816template <typename T> struct Base {
817  int x = 42;
818};
819Base<int> base;
820struct __declspec(dllexport) T : Base<int> { };
821// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::Base"* @"??0?$Base@H@InClassInits@@QAE@XZ"
822
823struct A { A(int); };
824struct __declspec(dllexport) U {
825  // Class with both default constructor closure and in-class initializer.
826  U(A = 0) {}
827  int x = 0;
828};
829// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::U"* @"??0U@InClassInits@@QAE@UA@1@@Z"
830
831struct Evil {
832  template <typename T> struct Base {
833    int x = 0;
834  };
835  struct S : Base<int> {};
836  // The already instantiated Base<int> becomes dllexported below, but the
837  // in-class initializer for Base<>::x still hasn't been parsed, so emitting
838  // the default ctor must still be delayed.
839  struct __declspec(dllexport) T : Base<int> {};
840};
841// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.InClassInits::Evil::Base"* @"??0?$Base@H@Evil@InClassInits@@QAE@XZ"
842
843template <typename T> struct Foo {};
844template <typename T> struct Bar {
845  Bar<T> &operator=(Foo<T>) {}
846};
847struct __declspec(dllexport) Baz {
848  Bar<int> n;
849};
850// After parsing Baz, in ActOnFinishCXXNonNestedClass we would synthesize
851// Baz's operator=, causing instantiation of Foo<int> after which
852// ActOnFinishCXXNonNestedClass is called, and we would bite our own tail.
853// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc dereferenceable(1) %"struct.InClassInits::Baz"* @"??4Baz@InClassInits@@QAEAAU01@ABU01@@Z"
854}
855
856// We had an issue where instantiating A would force emission of B's delayed
857// exported methods.
858namespace pr26490 {
859template <typename T> struct A { };
860struct __declspec(dllexport) B {
861  B(int = 0) {}
862  A<int> m_fn1() {}
863};
864// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FB@pr26490@@QAEXXZ"
865}
866
867// dllexport trumps dllimport on an explicit instantiation.
868template <typename T> struct ExplicitInstantiationTwoAttributes { void f() {} };
869template struct __declspec(dllexport) __declspec(dllimport) ExplicitInstantiationTwoAttributes<int>;
870// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?f@?$ExplicitInstantiationTwoAttributes@H@@QAEXXZ"
871
872namespace pr34849 {
873// Specializations of exported class template member functions get exported.
874template <typename> struct __declspec(dllexport) ExportedClassTemplate { void foo(); };
875template<> void ExportedClassTemplate<int>::foo() {}
876template struct ExportedClassTemplate<int>;
877// M32-DAG: define dso_local dllexport x86_thiscallcc void @"?foo@?$ExportedClassTemplate@H@pr34849@@QAEXXZ"
878
879// Specializations of exported class member template functions do not get exported.
880struct __declspec(dllexport) ExportedClass { template <typename> void bar() ; };
881template<> void ExportedClass::bar<int>() {}
882// M32-DAG: define dso_local x86_thiscallcc void @"??$bar@H@ExportedClass@pr34849@@QAEXXZ"
883template <typename> struct __declspec(dllexport) ExportedClassTemplate2 { template <typename> void baz(); };
884template<> template<> void ExportedClassTemplate2<int>::baz<int>() {}
885// M32-DAG: define dso_local x86_thiscallcc void @"??$baz@H@?$ExportedClassTemplate2@H@pr34849@@QAEXXZ"
886}
887
888//===----------------------------------------------------------------------===//
889// Classes with template base classes
890//===----------------------------------------------------------------------===//
891
892template <typename T> struct ClassTemplate { void func(); };
893template <typename T> void ClassTemplate<T>::func() {}
894template <typename T> struct __declspec(dllexport) ExportedClassTemplate { void func(); };
895template <typename T> void ExportedClassTemplate<T>::func() {}
896template <typename T> struct __declspec(dllimport) ImportedClassTemplate { void func(); };
897template <typename T> void ImportedClassTemplate<T>::func() {}
898
899template <typename T> struct ExplicitlySpecializedTemplate { void func() {} };
900template <> struct ExplicitlySpecializedTemplate<int> { void func(); };
901void ExplicitlySpecializedTemplate<int>::func() {}
902template <typename T> struct ExplicitlyExportSpecializedTemplate { void func() {} };
903template <> struct __declspec(dllexport) ExplicitlyExportSpecializedTemplate<int> { void func(); };
904void ExplicitlyExportSpecializedTemplate<int>::func() {}
905template <typename T> struct ExplicitlyImportSpecializedTemplate { void func(); };
906template <> struct __declspec(dllimport) ExplicitlyImportSpecializedTemplate<int> { void func(); };
907
908template <typename T> struct ExplicitlyInstantiatedTemplate { void func(); };
909template <typename T> void ExplicitlyInstantiatedTemplate<T>::func() {}
910template struct ExplicitlyInstantiatedTemplate<int>;
911template <typename T> struct ExplicitlyExportInstantiatedTemplate { void func(); };
912template <typename T> void ExplicitlyExportInstantiatedTemplate<T>::func() {}
913template struct __declspec(dllexport) ExplicitlyExportInstantiatedTemplate<int>;
914template <typename T> struct ExplicitlyImportInstantiatedTemplate { void func(); };
915template struct __declspec(dllimport) ExplicitlyImportInstantiatedTemplate<int>;
916
917
918// MS: ClassTemplate<int> gets exported.
919struct __declspec(dllexport) DerivedFromTemplate : public ClassTemplate<int> {};
920USEMEMFUNC(DerivedFromTemplate, func)
921// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$ClassTemplate@H@@QAEXXZ"
922// G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN13ClassTemplateIiE4funcEv
923
924// ExportedTemplate is explicitly exported.
925struct __declspec(dllexport) DerivedFromExportedTemplate : public ExportedClassTemplate<int> {};
926USEMEMFUNC(DerivedFromExportedTemplate, func)
927// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$ExportedClassTemplate@H@@QAEXXZ"
928// G32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @_ZN21ExportedClassTemplateIiE4funcEv
929
930// ImportedClassTemplate is explicitly imported.
931struct __declspec(dllexport) DerivedFromImportedTemplate : public ImportedClassTemplate<int> {};
932USEMEMFUNC(DerivedFromImportedTemplate, func)
933// M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"?func@?$ImportedClassTemplate@H@@QAEXXZ"
934// G32-DAG: declare dllimport x86_thiscallcc void @_ZN21ImportedClassTemplateIiE4funcEv
935
936// Base class already implicitly instantiated without dll attribute.
937struct DerivedFromTemplateD : public ClassTemplate<double> {};
938struct __declspec(dllexport) DerivedFromTemplateD2 : public ClassTemplate<double> {};
939USEMEMFUNC(DerivedFromTemplateD2, func)
940// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$ClassTemplate@N@@QAEXXZ"
941// G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN13ClassTemplateIdE4funcEv
942
943// MS: Base class already instantiated with different dll attribute.
944struct __declspec(dllimport) DerivedFromTemplateB : public ClassTemplate<bool> {};
945struct __declspec(dllexport) DerivedFromTemplateB2 : public ClassTemplate<bool> {};
946USEMEMFUNC(DerivedFromTemplateB2, func)
947// M32-DAG: {{declare|define available_externally}} dllimport x86_thiscallcc void @"?func@?$ClassTemplate@_N@@QAEXXZ"
948// G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN13ClassTemplateIbE4funcEv
949
950// Base class already specialized without dll attribute.
951struct __declspec(dllexport) DerivedFromExplicitlySpecializedTemplate : public ExplicitlySpecializedTemplate<int> {};
952USEMEMFUNC(DerivedFromExplicitlySpecializedTemplate, func)
953// M32-DAG: define dso_local x86_thiscallcc void @"?func@?$ExplicitlySpecializedTemplate@H@@QAEXXZ"
954// G32-DAG: define dso_local x86_thiscallcc void @_ZN29ExplicitlySpecializedTemplateIiE4funcEv
955
956// Base class alredy specialized with export attribute.
957struct __declspec(dllexport) DerivedFromExplicitlyExportSpecializedTemplate : public ExplicitlyExportSpecializedTemplate<int> {};
958USEMEMFUNC(DerivedFromExplicitlyExportSpecializedTemplate, func)
959// M32-DAG: define dso_local dllexport x86_thiscallcc void @"?func@?$ExplicitlyExportSpecializedTemplate@H@@QAEXXZ"
960// G32-DAG: define dso_local dllexport x86_thiscallcc void @_ZN35ExplicitlyExportSpecializedTemplateIiE4funcEv
961
962// Base class already specialized with import attribute.
963struct __declspec(dllexport) DerivedFromExplicitlyImportSpecializedTemplate : public ExplicitlyImportSpecializedTemplate<int> {};
964USEMEMFUNC(DerivedFromExplicitlyImportSpecializedTemplate, func)
965// M32-DAG: declare dllimport x86_thiscallcc void @"?func@?$ExplicitlyImportSpecializedTemplate@H@@QAEXXZ"
966// G32-DAG: declare dllimport x86_thiscallcc void @_ZN35ExplicitlyImportSpecializedTemplateIiE4funcEv
967
968// Base class already instantiated without dll attribute.
969struct __declspec(dllexport) DerivedFromExplicitlyInstantiatedTemplate : public ExplicitlyInstantiatedTemplate<int> {};
970USEMEMFUNC(DerivedFromExplicitlyInstantiatedTemplate, func)
971// M32-DAG: define weak_odr dso_local x86_thiscallcc void @"?func@?$ExplicitlyInstantiatedTemplate@H@@QAEXXZ"
972// G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN30ExplicitlyInstantiatedTemplateIiE4funcEv
973
974// Base class already instantiated with export attribute.
975struct __declspec(dllexport) DerivedFromExplicitlyExportInstantiatedTemplate : public ExplicitlyExportInstantiatedTemplate<int> {};
976USEMEMFUNC(DerivedFromExplicitlyExportInstantiatedTemplate, func)
977// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$ExplicitlyExportInstantiatedTemplate@H@@QAEXXZ"
978// G32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @_ZN36ExplicitlyExportInstantiatedTemplateIiE4funcEv
979
980// Base class already instantiated with import attribute.
981struct __declspec(dllexport) DerivedFromExplicitlyImportInstantiatedTemplate : public ExplicitlyImportInstantiatedTemplate<int> {};
982USEMEMFUNC(DerivedFromExplicitlyImportInstantiatedTemplate, func)
983// M32-DAG: declare dllimport x86_thiscallcc void @"?func@?$ExplicitlyImportInstantiatedTemplate@H@@QAEXXZ"
984// G32-DAG: declare dllimport x86_thiscallcc void @_ZN36ExplicitlyImportInstantiatedTemplateIiE4funcEv
985
986// MS: A dll attribute propagates through multiple levels of instantiation.
987template <typename T> struct TopClass { void func() {} };
988template <typename T> struct MiddleClass : public TopClass<T> { };
989struct __declspec(dllexport) BottomClass : public MiddleClass<int> { };
990USEMEMFUNC(BottomClass, func)
991// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$TopClass@H@@QAEXXZ"
992// G32-DAG: define linkonce_odr dso_local x86_thiscallcc void @_ZN8TopClassIiE4funcEv
993
994template <typename T> struct ExplicitInstantiationDeclTemplateBase { void func() {} };
995extern template struct ExplicitInstantiationDeclTemplateBase<int>;
996struct __declspec(dllexport) DerivedFromExplicitInstantiationDeclTemplateBase : public ExplicitInstantiationDeclTemplateBase<int> {};
997template struct ExplicitInstantiationDeclTemplateBase<int>;
998// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc void @"?func@?$ExplicitInstantiationDeclTemplateBase@H@@QAEXXZ"
999// G32-DAG: define weak_odr dso_local x86_thiscallcc void @_ZN37ExplicitInstantiationDeclTemplateBaseIiE4funcEv
1000
1001// PR26076
1002struct LayerSelectionBound;
1003template <typename> struct Selection {};
1004typedef Selection<LayerSelectionBound> LayerSelection;
1005struct LayerImpl;
1006struct __declspec(dllexport) LayerTreeImpl {
1007  struct __declspec(dllexport) ElementLayers {
1008    LayerImpl *main = nullptr;
1009  };
1010  LayerSelection foo;
1011};
1012// M32-DAG: define weak_odr dso_local dllexport x86_thiscallcc %"struct.LayerTreeImpl::ElementLayers"* @"??0ElementLayers@LayerTreeImpl@@QAE@XZ"
1013// M64-DAG: define weak_odr dso_local dllexport %"struct.LayerTreeImpl::ElementLayers"* @"??0ElementLayers@LayerTreeImpl@@QEAA@XZ"
1014
1015namespace pr39496 {
1016// Make sure dll attribute are inherited by static locals also in template
1017// specializations.
1018template <typename> struct __declspec(dllexport) S { int foo() { static int x; return x++; } };
1019int foo() { S<int> s; return s.foo(); }
1020// MSC-DAG: @"?x@?{{1|2}}??foo@?$S@H@pr39496@@Q{{[A-Z]*}}HXZ@4HA" = weak_odr dso_local dllexport global i32 0, comdat, align 4
1021
1022template <typename> struct T { int foo() { static int x; return x++; } };
1023template struct __declspec(dllexport) T<int>;
1024// MSC-DAG: @"?x@?{{1|2}}??foo@?$T@H@pr39496@@Q{{[A-Z]*}}HXZ@4HA" = weak_odr dso_local dllexport global i32 0, comdat, align 4
1025}
1026
1027class __declspec(dllexport) ACE_Shared_Object {
1028public:
1029  virtual ~ACE_Shared_Object();
1030};
1031class __declspec(dllexport) ACE_Service_Object : public ACE_Shared_Object {};
1032// Implicit move constructor declaration.
1033// MSVC2015-DAG: define weak_odr dso_local dllexport {{.+}}ACE_Service_Object@@Q{{.+}}@$$Q
1034// The declarations should not be exported.
1035// MSVC2013-NOT: define weak_odr dso_local dllexport {{.+}}ACE_Service_Object@@Q{{.+}}@$$Q
1036