[Bug c++/94904] New: [DR 1696] Temporary lifetime and non-static data member initializers

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri May 1 15:48:04 GMT 2020


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

            Bug ID: 94904
           Summary: [DR 1696] Temporary lifetime and non-static data
                    member initializers
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1696 should reject
the following three examples in all modes.

[dcl.init.aggr] If a reference member is initialized from its
brace-or-equal-initializer and a potentially-evaluated subexpression thereof is
an aggregate initialization that would use that brace-or-equal-initializer, the
program is ill-formed.

  struct A;
  extern A a;
  struct A {
    const A& a1 { A{a,a} };   // OK
    const A& a2 { A{} };      // error
  };
  A a{a,a};                   // OK

[class.base.init] A temporary expression bound to a reference member in a
mem-initializer is ill-formed.

  struct A {
    A() : v(42) { }  // error
    const int& v;
  };

[class.base.init] A temporary expression bound to a reference member from a
brace-or-equal-initializer is ill-formed.

  struct A {
    A() = default;          // OK
    A(int v) : v(v) { }     // OK
    const int& v = 42;      // OK
  };
  A a1;                     // error: ill-formed binding of temporary to
reference
  A a2(1);                  // OK, unfortunately


It might be possible also fix PR 63181 at the same time.


More information about the Gcc-bugs mailing list