[Bug c++/107402] New: Parenthesized aggregate initialization should not initialize references

ayzhao at google dot com gcc-bugzilla@gcc.gnu.org
Tue Oct 25 17:44:00 GMT 2022


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

            Bug ID: 107402
           Summary: Parenthesized aggregate initialization should not
                    initialize references
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ayzhao at google dot com
  Target Milestone: ---

The implementation of P0960R3 in
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91363> and
<https://gcc.gnu.org/legacy-ml/gcc-patches/2019-10/msg01578.html> allowed for
initialization of references by creating and initializing a temporary of the
referered type. Therefore, statements such as

 const MyStruct& m(1, 1);
 int (&&rr)[](1, 2, 3, 4); 

are accepted by GCC: <https://godbolt.org/z/WvEx6xE19>

A close reading of the C++ standard suggests that these expressions are not
allowed. Reference initialization via a temporary is described in
<http://eel.is/c++draft/dcl.init.ref#5.4>, and that only permits conversion by
constructor or conversion function (if the source or destination is of class
type) or implicit conversion, not arbitrary direct-initialization conversions
(which would include aggregate initialization)


More information about the Gcc-bugs mailing list