C++ Logo


Advanced search

Throwing noncopyable temporaries

From: Schneider, Robert <robert.schneider03_at_[hidden]>
Date: Thu, 1 Sep 2022 11:55:06 +0000

GCC and clang at the moment allow throwing of noncopyable prvalue expressions:

struct foo
    foo() = default;
    foo(foo const&) = delete;
    foo(foo&&) = delete;

void bar()
    throw foo();

I was wondering if that's intended, since I can't quite relate it to the wording of except.throw#5:

> When the thrown object is a class object, the constructor selected for the copy-initialization as well as the constructor selected for a copy-initialization considering the thrown object as an lvalue shall be non-deleted and accessible, even if the copy/move operation is elided ([class.copy.elision]).

As far as I understand, mandatory copy elision means that the constructor selected for copy-initialization in this case is the _default constructor_. Copy-initialization doesn't even consider copy/move constructors here. The part about "the thrown object as an lvalue" doesn't make sense to me in this context.

Anyway, was this change intended? Should the example above compile?


Received on 2022-09-01 11:55:09