This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

3229. §[res.on.exception.handling]#3 cannot apply to types with implicitly declared destructors

Section: 16.4.6.13 [res.on.exception.handling] Status: New Submitter: Nevin Liber Opened: 2019-06-28 Last modified: 2023-01-29

Priority: 3

View other active issues in [res.on.exception.handling].

View all other issues in [res.on.exception.handling].

View all issues with New status.

Discussion:

16.4.6.13 [res.on.exception.handling]#3 says:

Destructor operations defined in the C++ standard library shall not throw exceptions. Every destructor in the C++ standard library shall behave as if it had a non-throwing exception specification.

However, types like pair and array have implicitly declared destructors, where 14.5 [except.spec]#8 applies:

The exception specification for an implicitly-declared destructor, or a destructor without a noexcept-specifier, is potentially-throwing if and only if any of the destructors for any of its potentially constructed subobjects is potentially-throwing or the destructor is virtual and the destructor of any virtual base class is potentially throwing.

We can relax 16.4.6.13 [res.on.exception.handling] to only cover explicitly declared destructors because if they hold a user type where the destructor throws then we get UB from 16.4.5.8 [res.on.functions]#2:

In particular, the effects are undefined in the following cases: […]

  1. […]

  2. (2.4) — if any replacement function or handler function or destructor operation exits via an exception, unless specifically allowed in the applicable Required behavior: paragraph.

  3. […]

and the referred to UB happens before [res.on.exception.handling] could apply.

[2019-07 Issue Prioritization]

Priority to 3 after discussion on the reflector.

[2023-01-29; Daniel comments]

This issue has very much overlap with LWG 3854(i).

Proposed resolution:

This wording is relative to N4820.

  1. Modify 16.4.6.13 [res.on.exception.handling] as indicated:

    -3- Destructor operations defined in the C++ standard library shall not throw exceptions. Every explicitly declared destructor in the C++ standard library shall behave as if it had a non-throwing exception specification.