Skip to content

CWG2886 [class.temporary] noexcept operator with trivial but potentially-throwing special member functions #531

Description

@frederick-vs-ja

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [class.temporary]

Link to reflector thread (if any):

Issue description:

[class.temporary] p4 seemingly allows, but does not guarantee, that a trivial special member function is not called in the mentioned cases. As P1286R2 allowed trivial, eligible/non-deleted, but potentially-throwing (noexcept(false)) special member functions, the difference on whether such a special member function is called can be observed by a noexcept-expression.

There is implementation divergence on this (Godbolt link). It's unclear whether the implementation divergence is intended.

struct TrivialButPotentiallyThrowingDestructor {
    TrivialButPotentiallyThrowingDestructor() = default;
    ~TrivialButPotentiallyThrowingDestructor() noexcept(false) = default;
};

static_assert(noexcept(TrivialButPotentiallyThrowingDestructor{}), "???"); // EDG thinks the dtor is called, while others don't.

Also, it is unclear in [class.temporary] p3 whether the constructor or destructor call in the creation of a temporary object holding the function parameter is considered observable via a noexcept-expression. It seems intended that the implementation should only perform bitwise copy and the exception specification shouldn't be considered.

Suggested resolution:

Activity

  1. changed the title [-][class.temporary] `noexcept` with trivial but potentially-throwing special member functions[/-] [+][class.temporary] `noexcept` operator with trivial but potentially-throwing special member functions[/+] on Apr 27, 2024
  2. changed the title [-][class.temporary] `noexcept` operator with trivial but potentially-throwing special member functions[/-] [+]CWG2886 [class.temporary] `noexcept` operator with trivial but potentially-throwing special member functions[/+] on Apr 29, 2024
  3. jensmaurer commented on Apr 29, 2024

    @jensmaurer
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions