[Bug c++/88572] error: braces around scalar initializer - should be a warning

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Jan 7 15:19:00 GMT 2019


--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The relevant code is:

      /* It is invalid to initialize a non-aggregate type with a
         brace-enclosed initializer before C++0x.
         We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
         of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
         a CONSTRUCTOR (with a record type).  */
      if (TREE_CODE (stripped_init) == CONSTRUCTOR
          /* Don't complain about a capture-init.  */
          && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
          && BRACE_ENCLOSED_INITIALIZER_P (stripped_init))  /* p7626.C */
          if (SCALAR_TYPE_P (type))
              if (cxx_dialect < cxx11
                  /* Isn't value-initialization.  */
                  || CONSTRUCTOR_NELTS (stripped_init) > 0)
                  if (complain & tf_error)
                    error ("braces around scalar initializer for type %qT",
                  init = error_mark_node;

The condition means we give an error for any braced-init-list in C++98, and for
a non-empty braced-init-list in later dialects . But the latter condition is
wrong, it should allow a single element (and presumably more than one element
will be rejected as an invalid initializer anyway).

I'm not even sure we should warn about this.

More information about the Gcc-bugs mailing list