CWG Issue 2854 (original) (raw)

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

2025-04-13


2854. Storage duration of exception objects

Section: 14.2 [except.throw]Status: DRWPSubmitter: Jiang AnDate: 2024-01-22

[Accepted as a DR at the March, 2024 meeting.]

(From submission#492.)

According to 14.2 [except.throw] paragraph 3, the exception object is a temporary object. But none of the possible storage durations of temporary objects matches the behavior of exception objects.

Proposed resolution (approved by CWG 2024-02-16):

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

    Temporary objects are created

    • when a prvalue is converted to an xvalue (7.3.5 [conv.rval]), and
    • when needed by the implementation to pass or return an object of trivially copyable type (see below), and.
    • when throwing an exception (14.2 [except.throw]). [_Note 1:_ The lifetime of exception objects is described in 14.2 [except.throw]. —_end note_]
      ...
  2. Change in 14.2 [except.throw] paragraph 3 as follows:

    Throwing an exception initializes a temporary anobject with dynamic storage duration, called the exception object. If the type of the exception object would be an incomplete type (6.8.1 [basic.types.general]), an abstract class type (11.7.4 [class.abstract]), or a pointer to an incomplete type other than cv void (6.8.4 [basic.compound]) the program is ill-formed.