You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 1, 2021. It is now read-only.
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
Copy file name to clipboardExpand all lines: test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p9.cpp
+2-2
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ extern int (*const d)(int);
17
17
18
18
// A variable declaration which uses the constexpr specifier shall have an
19
19
// initializer and shall be initialized by a constant expression.
20
-
constexprint ni1; // expected-error {{default initialization of an object of const type 'const int'}} expected-note {{add an explicit initializer to initialize 'ni1'}}
20
+
constexprint ni1; // expected-error {{default initialization of an object of const type 'const int'}}
21
21
constexprstructC { C(); } ni2; // expected-error {{cannot have non-literal type 'const struct C'}} expected-note 3{{has no constexpr constructors}}
22
22
constexprdouble &ni3; // expected-error {{declaration of reference variable 'ni3' requires an initializer}}
23
23
@@ -34,4 +34,4 @@ struct pixel {
34
34
int x, y;
35
35
};
36
36
constexpr pixel ur = { 1294, 1024 }; // ok
37
-
constexpr pixel origin; // expected-error {{default initialization of an object of const type 'const pixel' without a user-provided default constructor}} expected-note {{add an explicit initializer to initialize 'origin'}}
37
+
constexpr pixel origin; // expected-error {{default initialization of an object of const type 'const pixel' without a user-provided default constructor}}
Copy file name to clipboardExpand all lines: test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+2-2
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ struct S3 {
36
36
constexpr S3 s3a = S3(0);
37
37
constexpr S3 s3b = s3a;
38
38
constexpr S3 s3c = S3();
39
-
constexpr S3 s3d; // expected-error {{default initialization of an object of const type 'const S3' without a user-provided default constructor}} expected-note{{add an explicit initializer to initialize 's3d'}}
39
+
constexpr S3 s3d; // expected-error {{default initialization of an object of const type 'const S3' without a user-provided default constructor}}
40
40
41
41
structS4 {
42
42
S4() = default;
@@ -119,6 +119,6 @@ namespace PR13492 {
119
119
};
120
120
121
121
voidf() {
122
-
const B b; // expected-error {{default initialization of an object of const type 'const PR13492::B' without a user-provided default constructor}} expected-note {{add an explicit initializer to initialize 'b'}}
122
+
const B b; // expected-error {{default initialization of an object of const type 'const PR13492::B' without a user-provided default constructor}}
const NoUserDefault x1; // expected-error{{default initialization of an object of const type 'const NoUserDefault' without a user-provided default constructor}} expected-note {{add an explicit initializer to initialize 'x1'}}
13
+
const NoUserDefault x1; // expected-error{{default initialization of an object of const type 'const NoUserDefault' without a user-provided default constructor}}
14
14
const HasUserDefault x2;
15
-
constint x3; // expected-error{{default initialization of an object of const type 'const int'}} expected-note{{add an explicit initializer to initialize 'x3'}}
15
+
constint x3; // expected-error{{default initialization of an object of const type 'const int'}}
16
16
}
17
17
18
18
// rdar://8501008
19
19
structs0 {};
20
20
structs1 { staticconst s0 foo; };
21
-
conststructs0 s1::foo; // expected-error{{default initialization of an object of const type 'const struct s0' without a user-provided default constructor}} expected-note {{add an explicit initializer to initialize 'foo'}}
21
+
conststructs0 s1::foo; // expected-error{{default initialization of an object of const type 'const struct s0' without a user-provided default constructor}}
__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);
34
34
35
35
namespace { classInternal {}; }
36
36
__declspec(selectany) auto x8 = Internal(); // expected-error {{'selectany' can only be applied to data items with external linkage}}
37
+
38
+
39
+
// The D3D11 headers do something like this. MSVC doesn't error on this at
40
+
// all, even without the __declspec(selectany), in violation of the standard.
41
+
// We fall back to a warning for selectany to accept headers.
42
+
structSomeStruct {};
43
+
externconst__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}}
44
+
45
+
// Without selectany, this should stay an error.
46
+
const SomeStruct some_struct2; // expected-error {{default initialization of an object of const type 'const SomeStruct' without a user-provided default constructor}}
Copy file name to clipboardExpand all lines: test/SemaCXX/cxx0x-cursory-default-delete.cpp
+1-1
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ void fn1 () {
25
25
non_const_copy ncc2 = ncc;
26
26
ncc = ncc2;
27
27
const non_const_copy cncc{};
28
-
const non_const_copy cncc1; // expected-error {{default initialization of an object of const type 'const non_const_copy' without a user-provided default constructor}} expected-note {{add an explicit initializer to initialize 'cncc1'}}
28
+
const non_const_copy cncc1; // expected-error {{default initialization of an object of const type 'const non_const_copy' without a user-provided default constructor}}
Copy file name to clipboardExpand all lines: test/SemaCXX/cxx1y-variable-templates_in_class.cpp
+2-2
Original file line number
Diff line number
Diff line change
@@ -58,13 +58,13 @@ namespace out_of_line {
58
58
template<typename T, typename T0> static CONST T b = T(100);
59
59
template<typename T> static CONST T b<T,int>;
60
60
};
61
-
template<typename T, typename T0> CONST T B4::a; // expected-error {{default initialization of an object of const type 'const int'}} expected-note {{add an explicit initializer to initialize 'a<int, char>'}}
61
+
template<typename T, typename T0> CONST T B4::a; // expected-error {{default initialization of an object of const type 'const int'}}
62
62
template<typename T> CONST T B4::a<T,int>;
63
63
template CONST int B4::a<int,char>; // expected-note {{in instantiation of}}
64
64
template CONST int B4::a<int,int>;
65
65
66
66
template<typename T, typename T0> CONST T B4::b;
67
-
template<typename T> CONST T B4::b<T,int>; // expected-error {{default initialization of an object of const type 'const int'}} expected-note {{add an explicit initializer to initialize 'b<int, int>'}}
67
+
template<typename T> CONST T B4::b<T,int>; // expected-error {{default initialization of an object of const type 'const int'}}
68
68
template CONST int B4::b<int,char>;
69
69
template CONST int B4::b<int,int>; // expected-note {{in instantiation of}}
0 commit comments