C++ Logo


Advanced search

Re: Throwing noncopyable temporaries

From: Jiang An <de34_at_[hidden]>
Date: Fri, 02 Sep 2022 07:51:47 +0800
I think it's intended that only exception objects of copy constructible types are supported.

Conditionally-supported non-copyable types may be supported de jure in future, but a paper is needed. See also https://github.com/cplusplus/CWG/issues/35 .

Jiang An

在 "Schneider, Robert via Std-Discussion" <std-discussion_at_[hidden]>,2022年9月1日 19:55写道:


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?

Std-Discussion mailing list

Received on 2022-09-01 23:52:01