Title
Consteval destructor through immediate escalation
Status
ready
Section
7.7 [expr.const]
Submitter
Corentin Jabot

Created on 2025-10-14.00:00:00 last changed 1 month ago

Messages

Date: 2025-11-05.12:07:23

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

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

An immediate-escalating function is
  • the call operator of a lambda that is not declared with the consteval specifier,
  • a defaulted special member function that is not declared with the consteval specifier, or
  • a function that is not a prospective destructor and that results from the instantiation of a templated entity defined with the constexpr specifier.
Date: 2025-11-05.12:07:23

(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.

History
Date User Action Args
2025-11-07 22:16:49adminsetstatus: tentatively ready -> ready
2025-11-05 12:07:23adminsetmessages: + msg8215
2025-11-05 12:07:23adminsetstatus: open -> tentatively ready
2025-10-14 00:00:00admincreate