This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 116a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-12-19


2941. Lifetime extension for function-style cast to reference type

Section: 6.7.7  [class.temporary]     Status: open     Submitter: Hubert Tong     Date: 2024-10-18

(From submission #625.)

Issue 2894 will clarify that a function-style cast to reference type produces a glvalue, not a prvalue. However, 6.7.7 [class.temporary] does not specify lifetime-extension for this case, even though implementations uniformly do extend the lifetime.

For example:

  int glob;
  struct A {
   constexpr ~A() { p = &glob; }
   int *p;
  };
  constexpr int f() {
   typedef const A &AR;
   const A &ref = AR{0};
   delete ref.p;
   return 0;
  }
  extern constexpr int x = f(); // okay

Suggested resolution:

Change in 6.7.7 [class.temporary] paragraph 6 as follows: