[cfe-dev] 'braces around scalar initializer' warning, should be error?

will wray via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 18 12:16:46 PST 2018


*    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
<http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#632>
explains that this was a C/C++ incompatibility, says it was resolved
by Initializer
Lists <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm>
(LOL) (I can't see how or where it is resolved)
h1501. Nested braces in list-initialization
<http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1501>
As part of changes for DR1467 List-initialization of aggregate from
same-type object
<http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1467>
this Clang commit
r228896
<http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20150209/123171.html>-
Improve the "braces around scalar init" warning to determine whether to warn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181218/8602409a/attachment.html>


More information about the cfe-dev mailing list