Bug 94904 - [DR 1696] Temporary lifetime and non-static data member initializers
Summary: [DR 1696] Temporary lifetime and non-static data member initializers
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2020-05-01 15:48 UTC by Jonathan Wakely
Modified: 2020-05-02 11:24 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-05-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.