Bug 94904

Summary: [DR 1696] Temporary lifetime and non-static data member initializers
Product: gcc Reporter: Jonathan Wakely <redi>
Component: c++Assignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: daniel.kruegler, gabravier, mpolacek, webrown.cpp
Priority: P3 Keywords: accepts-invalid
Version: 10.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63181
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2020-05-01 00:00:00

Description Jonathan Wakely 2020-05-01 15:48:04 UTC
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.