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

2025-11-07


3105. Consteval destructor through immediate escalation

Section: 7.7  [expr.const]     Status: ready     Submitter: Corentin Jabot     Date: 2025-10-14

(From submission #780.)

Consider:

  consteval void undefined();
  template <typename T>
  struct scope_exit {
    T t;
    constexpr ~scope_exit() { t(); }   // #2
  };

  scope_exit guard([]() { 
    undefined();                       // # 1
  });

#1 is an immediate escalating expression (because undefined is not defined) and ~scope_exit() is instantiated from a constexpr templated entity #2, thus is immediate escalating. Finally, this causes ~scope_exit to be an immediate function.

However, destructors cannot be consteval.

Proposed resolution (approved by CWG 2025-11-04):

Change in 7.7 [expr.const] paragraph 26 as follows:

An immediate-escalating function is