1 // RUN: %clang_cc1 -std=c++14 %s -verify -fms-extensions -triple x86_64-windows-msvc
2 // RUN: %clang_cc1 -std=c++17 %s -verify -fms-extensions -triple x86_64-windows-msvc
4 __declspec(dllimport
) void imported_func();
5 __declspec(dllimport
) int imported_int
;
7 void __declspec(dllimport
) imported_method();
10 // Instantiation is OK.
11 template <void (*FP
)()> struct TemplateFnPtr
{
12 static void getit() { FP(); }
14 template <void (&FP
)()> struct TemplateFnRef
{
15 static void getit() { FP(); }
18 TemplateFnPtr
<&imported_func
>::getit();
19 TemplateFnRef
<imported_func
>::getit();
22 // Check variable template instantiation.
23 template <int *GI
> struct TemplateIntPtr
{
24 static int getit() { return *GI
; }
26 template <int &GI
> struct TemplateIntRef
{
27 static int getit() { return GI
; }
31 r
+= TemplateIntPtr
<&imported_int
>::getit();
32 r
+= TemplateIntRef
<imported_int
>::getit();
36 // Member pointer instantiation.
37 template <void (Foo::*MP
)()> struct TemplateMemPtr
{ };
38 TemplateMemPtr
<&Foo::imported_method
> instantiate_mp
;
40 // constexpr initialization doesn't work for dllimport things.
41 // expected-error@+1{{must be initialized by a constant expression}}
42 constexpr void (*constexpr_import_func
)() = &imported_func
;
43 // expected-error@+1{{must be initialized by a constant expression}}
44 constexpr int *constexpr_import_int
= &imported_int
;
45 // expected-error@+1{{must be initialized by a constant expression}}
46 constexpr void (Foo::*constexpr_memptr
)() = &Foo::imported_method
;
48 // We make dynamic initializers for 'const' globals, but not constexpr ones.
49 void (*const const_import_func
)() = &imported_func
;
50 int *const const_import_int
= &imported_int
;
51 void (Foo::*const const_memptr
)() = &Foo::imported_method
;
53 // Check that using a non-type template parameter for constexpr global
54 // initialization is correctly diagnosed during template instantiation.
55 template <void (*FP
)()> struct StaticConstexpr
{
56 // expected-error@+1{{must be initialized by a constant expression}}
57 static constexpr void (*g_fp
)() = FP
;
60 // expected-note@+1 {{requested here}}
61 StaticConstexpr
<imported_func
>::g_fp();