summaryrefslogtreecommitdiff
path: root/test/SemaCXX/attr-selectany.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2015-04-17 08:32:38 +0000
committerNico Weber <nicolasweber@gmx.de>2015-04-17 08:32:38 +0000
commitc40b644374e695f1d324a7d840c6c3a2009e8616 (patch)
treefc66e5c9769372e645b3efaeff499c5104581863 /test/SemaCXX/attr-selectany.cpp
parent8dcb1024652297cd961d7cf27524f6afaf4ff1fc (diff)
downloadclang-c40b644374e695f1d324a7d840c6c3a2009e8616.tar.gz
Move fixit for const init from note to diag, weaken to warning in MS mode.
r235046 turned "extern __declspec(selectany) int a;" from a declaration into a definition to fix PR23242 (required for compatibility with mc.exe output). However, this broke parsing Windows headers: A d3d11 headers contain something like struct SomeStruct {}; extern const __declspec(selectany) SomeStruct some_struct; This is now a definition, and const objects either need an explicit default ctor or an initializer so this errors out with d3d11.h(1065,48) : error: default initialization of an object of const type 'const CD3D11_DEFAULT' without a user-provided default constructor (cl.exe just doesn't implement this rule, independent of selectany.) To work around this, weaken this error into a warning for selectany decls in microsoft mode, and recover with zero-initialization. Doing this is a bit hairy since it adds a fixit on an error emitted by InitializationSequence – this means it needs to build a correct AST, which in turn means InitializationSequence::Failed() cannot return true when this fixit is applied. As a workaround, the patch adds a fixit member to InitializationSequence, and InitializationSequence::Perform() prints the diagnostic if the fixit member is set right after its call to Diagnose. That function is usually called when InitializationSequences are used – InitListChecker::PerformEmptyInit() doesn't call it, but the InitListChecker case never performs default-initialization, so this is technically OK. This is the alternative, original fix for PR20208 that got reviewed in the thread "[patch] Improve diagnostic on default-initializing const variables (PR20208)". This change basically reverts r213725, adds the original fix for PR20208, and makes the error a warning in Microsoft mode. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235166 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/attr-selectany.cpp')
-rw-r--r--test/SemaCXX/attr-selectany.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/test/SemaCXX/attr-selectany.cpp b/test/SemaCXX/attr-selectany.cpp
index c27a915921..7d9cf7aea4 100644
--- a/test/SemaCXX/attr-selectany.cpp
+++ b/test/SemaCXX/attr-selectany.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
// MSVC produces similar diagnostics.
__declspec(selectany) void foo() { } // expected-error{{'selectany' can only be applied to data items with external linkage}}
@@ -34,3 +34,13 @@ __declspec(selectany) X x(1);
namespace { class Internal {}; }
__declspec(selectany) auto x8 = Internal(); // expected-error {{'selectany' can only be applied to data items with external linkage}}
+
+
+// The D3D11 headers do something like this. MSVC doesn't error on this at
+// all, even without the __declspec(selectany), in violation of the standard.
+// We fall back to a warning for selectany to accept headers.
+struct SomeStruct {};
+extern const __declspec(selectany) SomeStruct some_struct; // expected-warning {{default initialization of an object of const type 'const SomeStruct' without a user-provided default constructor is a Microsoft extension}}
+
+// Without selectany, this should stay an error.
+const SomeStruct some_struct2; // expected-error {{default initialization of an object of const type 'const SomeStruct' without a user-provided default constructor}}