llvm-project/clang/test/CXX/dcl.dcl
Nico Weber 337d5aa58f 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
2015-04-17 08:32:38 +00:00
..
basic.namespace Sema: Don't dyn_cast a null pointer in CheckUsingDeclQualifier 2014-12-17 02:41:36 +00:00
dcl.attr AST: Don't ignore alignas on EnumDecls when calculating alignment 2015-01-21 10:54:38 +00:00
dcl.enum PR18400: ignore cv-qualifiers on the underlying type of an enumeration. 2014-01-08 01:16:19 +00:00
dcl.link More tests for r201536. 2014-02-18 22:47:10 +00:00
dcl.spec Move fixit for const init from note to diag, weaken to warning in MS mode. 2015-04-17 08:32:38 +00:00
p4-0x.cpp The 'constexpr implies const' rule for non-static member functions is gone in 2013-04-21 01:08:50 +00:00