[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

or, with more braces:

 `*warning*: too many braces around scalar initializer
(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
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
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

Thanks for any thoughts,

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 <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
As part of changes for DR1467 List-initialization of aggregate from
same-type object
this Clang commit
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