diff options
author | Nico Weber <nicolasweber@gmx.de> | 2015-04-17 08:32:38 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2015-04-17 08:32:38 +0000 |
commit | 337d5aa58fc22dd174dd6e9e96a764cf5a85f1fc (patch) | |
tree | 6943da87d7ad02fe16b585e345d325fd2124d585 /clang/test/FixIt/fixit.cpp | |
parent | 607da974b2a4de3bc4f2d016c9c6c2dfe9bc8471 (diff) | |
download | bcm5719-llvm-337d5aa58fc22dd174dd6e9e96a764cf5a85f1fc.tar.gz bcm5719-llvm-337d5aa58fc22dd174dd6e9e96a764cf5a85f1fc.zip |
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.
llvm-svn: 235166
Diffstat (limited to 'clang/test/FixIt/fixit.cpp')
-rw-r--r-- | clang/test/FixIt/fixit.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/test/FixIt/fixit.cpp b/clang/test/FixIt/fixit.cpp index 6c2fb7faf14..512713aa529 100644 --- a/clang/test/FixIt/fixit.cpp +++ b/clang/test/FixIt/fixit.cpp @@ -387,3 +387,11 @@ struct conversion_operator { // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:32}:"" // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:44-[[@LINE-2]]:44}:" conversion_operator::* const" }; + +struct const_zero_init { + int a; +}; +const const_zero_init czi; // expected-error {{default initialization of an object of const type 'const const_zero_init'}} +// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:26-[[@LINE-1]]:26}:"{}" +int use_czi = czi.a; + |