https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88572

--- Comment #1 from Will Wray <wjwray at gmail dot com> ---
This bug is straightforward to confirm.
Compile this snippet (-std=c++11 / 14 / 17 / 2a):

    struct S { int i; };
    S s{{0}};

Gives       error: braces around scalar initializer for type 'int'
Should be a warning

(Or, follow the provided compiler explorer link to the test code
 which includes two more failing cases - array and array member.)

The standard is clear that scalar brace init should be accepted:

C++14 [dcl.init.aggr]/2 says:
    "Each member is copy-initialized from the corresponding initializer-clause.
[...] [ Note: If an initializer-clause is itself an initializer list, the
member is list-initialized, which will result in a recursive application of the
rules in this section if the member is an aggregate.  — end note ]"

C++14 [dcl.init.list]/3.5:
    "Otherwise, if the initializer list has a single element of type E and
either T is not a reference type or its referenced type is reference-related to
E, the object or reference is initialized from that element;"


Some historical links leading up to the wording fixes:

DR 155. Brace initializer for scalar
     Explains it was a C/C++ incompatibility pre-11 and points to:

DR 632. Brace-enclosed initializer for scalar member of aggregate
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#632
      "The initializer-list proposal will resolve this issue..."

As stated, it was resolved in C++11 by Initializer Lists:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2672.htm

1501. Nested braces in list-initialization
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#1501

DR1467 List-initialization of aggregate from same-type object
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1467
  Submitter: Jason Merrill     Date: 2012-02-06
 [Moved to DR at the November, 2014 meeting.]

Please CONFIRM this bug.

Reply via email to