struct S { int i; };
S s{{0}};
Clang: **warning**: braces around scalar initializer [-Wbraced-scalar-init]
or, with more braces:
`warning: too many braces around scalar initializer [-Wmany-braces-around-scalar-init]
(consistent as a warning since at least clang 3.0.0)
GCC: **error**: braces around scalar initializer for type 'int'
(consistent as an error since ~gcc 4.4.7)
MSVC: no warning (with \Wall)
Intel: warning #1119: extra braces are nonstandard
I believe that this is a non-standard extension in Clang. Can anyone confirm?
Does the standard does mandate an error here?
If so then is there any flag to make this an error in Clang?
(-pedantic-errors flag makes no difference, for gcc or for clang.)
Maybe it’s for MSVC / EDG compatibility? Or C compatibility? What reason?
An error allows compile-time code to distinguish between scalar and non-scalar,
to count the number of allowable braces and so to detect array rank & dims.
On the other hand, an error forces different syntax for initializing scalar and non-scalar
so disallows generic ‘uniform’ braced-init syntax where there may be scalars.
Thanks for any thoughts,
Will
Here are some issues/DRs & commits that may or may not be relevant
An old pre-11 issue
632. Brace-enclosed initializer for scalar member of aggregate
explains that this was a C/C++ incompatibility, says it was resolved by Initializer Lists
(LOL) (I can’t see how or where it is resolved)
h1501. Nested braces in list-initialization
As part of changes for DR1467 List-initialization of aggregate from same-type object
this Clang commit
r228896 - Improve the “braces around scalar init” warning to determine whether to warn