summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2018-05-10 18:57:35 +0000
committerReid Kleckner <rnk@google.com>2018-05-10 18:57:35 +0000
commit1a840d29b417e393c3d229706c912a97d015ed41 (patch)
tree02912cb96dfdb0bf4530e39ab21db0f80f12a9b7 /clang/test
parent175400a801340a75c8fcd5c30924540ae84ad90f (diff)
downloadbcm5719-llvm-1a840d29b417e393c3d229706c912a97d015ed41.tar.gz
bcm5719-llvm-1a840d29b417e393c3d229706c912a97d015ed41.zip
Allow dllimport non-type template arguments in C++17
Summary: Fixes PR35772. Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D43320 llvm-svn: 332018
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaCXX/dllimport-constexpr.cpp62
-rw-r--r--clang/test/SemaCXX/dllimport-memptr.cpp1
2 files changed, 63 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/dllimport-constexpr.cpp b/clang/test/SemaCXX/dllimport-constexpr.cpp
new file mode 100644
index 00000000000..95d75b906f9
--- /dev/null
+++ b/clang/test/SemaCXX/dllimport-constexpr.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++14 %s -verify -fms-extensions -triple x86_64-windows-msvc
+// RUN: %clang_cc1 -std=c++17 %s -verify -fms-extensions -triple x86_64-windows-msvc
+
+__declspec(dllimport) void imported_func();
+__declspec(dllimport) int imported_int;
+struct Foo {
+ void __declspec(dllimport) imported_method();
+};
+
+// Instantiation is OK.
+template <void (*FP)()> struct TemplateFnPtr {
+ static void getit() { FP(); }
+};
+template <void (&FP)()> struct TemplateFnRef {
+ static void getit() { FP(); }
+};
+void instantiate1() {
+ TemplateFnPtr<&imported_func>::getit();
+ TemplateFnRef<imported_func>::getit();
+}
+
+// Check variable template instantiation.
+template <int *GI> struct TemplateIntPtr {
+ static int getit() { return *GI; }
+};
+template <int &GI> struct TemplateIntRef {
+ static int getit() { return GI; }
+};
+int instantiate2() {
+ int r = 0;
+ r += TemplateIntPtr<&imported_int>::getit();
+ r += TemplateIntRef<imported_int>::getit();
+ return r;
+}
+
+// Member pointer instantiation.
+template <void (Foo::*MP)()> struct TemplateMemPtr { };
+TemplateMemPtr<&Foo::imported_method> instantiate_mp;
+
+// constexpr initialization doesn't work for dllimport things.
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr void (*constexpr_import_func)() = &imported_func;
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr int *constexpr_import_int = &imported_int;
+// expected-error@+1{{must be initialized by a constant expression}}
+constexpr void (Foo::*constexpr_memptr)() = &Foo::imported_method;
+
+// We make dynamic initializers for 'const' globals, but not constexpr ones.
+void (*const const_import_func)() = &imported_func;
+int *const const_import_int = &imported_int;
+void (Foo::*const const_memptr)() = &Foo::imported_method;
+
+// Check that using a non-type template parameter for constexpr global
+// initialization is correctly diagnosed during template instantiation.
+template <void (*FP)()> struct StaticConstexpr {
+ // expected-error@+1{{must be initialized by a constant expression}}
+ static constexpr void (*g_fp)() = FP;
+};
+void instantiate3() {
+ // expected-note@+1 {{requested here}}
+ StaticConstexpr<imported_func>::g_fp();
+}
diff --git a/clang/test/SemaCXX/dllimport-memptr.cpp b/clang/test/SemaCXX/dllimport-memptr.cpp
index 35bf5b8610b..937384e8234 100644
--- a/clang/test/SemaCXX/dllimport-memptr.cpp
+++ b/clang/test/SemaCXX/dllimport-memptr.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fms-extensions -verify -std=c++17 %s
// expected-no-diagnostics
OpenPOWER on IntegriCloud