summaryrefslogtreecommitdiff
path: root/test/Sema
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2019-03-19 14:53:52 +0000
committerAaron Ballman <aaron@aaronballman.com>2019-03-19 14:53:52 +0000
commit7879e0e4c7ec13d63d75202b91fac028e4088f29 (patch)
treed8c7dbd9616d6e80c4e149f9b0d1820eaf602426 /test/Sema
parentf6f53c0d9bc5c14a4cc1ebd9dfb9ae01fc570703 (diff)
downloadclang-7879e0e4c7ec13d63d75202b91fac028e4088f29.tar.gz
Ensure that const variables declared at namespace scope correctly have external linkage when marked as dllexport and targeting the MSVC ABI.
Patch thanks to Zahira Ammarguellat. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356458 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema')
-rw-r--r--test/Sema/dllexport-1.cpp33
-rw-r--r--test/Sema/dllexport-2.cpp26
2 files changed, 59 insertions, 0 deletions
diff --git a/test/Sema/dllexport-1.cpp b/test/Sema/dllexport-1.cpp
new file mode 100644
index 0000000000..6180d35669
--- /dev/null
+++ b/test/Sema/dllexport-1.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -fms-extensions -verify %s
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsyntax-only -fms-extensions -verify %s -DMSVC
+
+// Export const variable initialization.
+
+#ifdef MSVC
+// expected-no-diagnostics
+#endif
+
+#ifndef MSVC
+// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}}
+#endif
+__declspec(dllexport) int const x = 3;
+
+namespace {
+namespace named {
+#ifndef MSVC
+// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}}
+#endif
+__declspec(dllexport) int const x = 3;
+}
+} // namespace
+
+namespace named1 {
+namespace {
+namespace named {
+#ifndef MSVC
+// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}}
+#endif
+__declspec(dllexport) int const x = 3;
+}
+} // namespace
+} // namespace named1
diff --git a/test/Sema/dllexport-2.cpp b/test/Sema/dllexport-2.cpp
new file mode 100644
index 0000000000..41d96cc4e6
--- /dev/null
+++ b/test/Sema/dllexport-2.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -fms-extensions -verify %s
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsyntax-only -fms-extensions -verify %s -DMSVC
+
+// Export const variable.
+
+#ifdef MSVC
+// expected-error@+4 {{'j' must have external linkage when declared 'dllexport'}}
+#else
+// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}}
+#endif
+__declspec(dllexport) int const j; // expected-error {{default initialization of an object of const type 'const int'}}
+
+// With typedef
+typedef const int CInt;
+
+#ifdef MSVC
+// expected-error@+4 {{'j2' must have external linkage when declared 'dllexport'}}
+#else
+// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}}
+#endif
+__declspec(dllexport) CInt j2; //expected-error {{default initialization of an object of const type 'CInt'}}
+
+#ifndef MSVC
+// expected-warning@+2 {{__declspec attribute 'dllexport' is not supported}}
+#endif
+__declspec(dllexport) CInt j3 = 3;