91 lines · cpp
1// RUN: %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s2// RUN: %clang_cc1 %s -triple=x86_64-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s3// RUN: %clang_cc1 %s -triple=i686-pc-windows-msvc -fms-extensions -emit-llvm -o - | FileCheck %s4// RUN: %clang_cc1 %s -triple=x86_64-pc-windows-msvc -fms-extensions -emit-llvm -o - | FileCheck %s5 6struct S {7 S();8 ~S();9};10 11template <typename T> struct __declspec(dllexport) ExportedTemplate {12 static S s;13};14template <typename T> S ExportedTemplate<T>::s;15void useExportedTemplate(ExportedTemplate<int> x) {16 (void)x.s;17}18int f();19namespace selectany_init {20// MS don't put selectany static var in the linker directive, init routine21// f() is not getting called if x is not referenced.22int __declspec(selectany) x = f();23inline int __declspec(selectany) x1 = f();24}25 26namespace explicit_template_instantiation {27template <typename T> struct A { static int x; };28template <typename T> int A<T>::x = f();29template struct A<int>;30}31 32namespace implicit_template_instantiation {33template <typename T> struct A { static int x; };34template <typename T> int A<T>::x = f();35int g() { return A<int>::x; }36}37 38 39template <class T>40struct X_ {41 static T ioo;42 static T init();43};44template <class T> T X_<T>::ioo = X_<T>::init();45template struct X_<int>;46 47template <class T>48struct X {49 static T ioo;50 static T init();51};52template <> int X<int>::ioo = X<int>::init();53template struct X<int>;54class a {55public:56 a();57};58// For the static var inside unnamed namespace, the object is local to TU.59// No need to put static var in the linker directive.60// The static init routine is called before main.61namespace {62template <int> class aj {63public:64 static a al;65};66template <int am> a aj<am>::al;67class b : aj<3> {68 void c();69};70void b::c() { al; }71}72 73// C++17, inline static data member also need to use74struct A75{76 A();77 ~A();78};79 80struct S181{82 inline static A aoo; // C++17 inline variable, thus also a definition83};84 85int foo();86inline int zoo = foo();87inline static int boo = foo();88inline __declspec(dllexport) A exported_inline{};89 90// CHECK: @llvm.used = appending global [10 x ptr] [ptr @"?x@selectany_init@@3HA", ptr @"?x1@selectany_init@@3HA", ptr @"?x@?$A@H@explicit_template_instantiation@@2HA", ptr @"?ioo@?$X_@H@@2HA", ptr @"?ioo@?$X@H@@2HA", ptr @"?aoo@S1@@2UA@@A", ptr @"?zoo@@3HA", ptr @"?exported_inline@@3UA@@A", ptr @"?s@?$ExportedTemplate@H@@2US@@A", ptr @"?x@?$A@H@implicit_template_instantiation@@2HA"], section "llvm.metadata"91