Movatterモバイル変換


[0]ホーム

URL:



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

2116.is_nothrow_constructible and destructors

Section: 21.3.6.4[meta.unary.prop]Status:OpenSubmitter: Dave AbrahamsOpened: 2011-12-09Last modified: 2023-05-25

Priority:3

View otheractive issues in [meta.unary.prop].

View all otherissues in [meta.unary.prop].

View all issues withOpen status.

Discussion:

IMO if we specifiedis_[nothrow_]constructible in terms of a variabledeclaration whose validity requires destructibility, it is clearly a bugin our specification and a failure to realize the actual originalintent. The specification should have been in terms of placement-new.

Daniel:
At the time of the specification this was intended and the solution isnot done by removing the destruction semantics ofis_constructible.

The design ofis_constructible was also impacted by the previousConstructible concept thatexplicitly contained destruction semantics,because during conceptification of the library it turned out to simplifythe constraints in the library because you did not need to addDestructible all the time. It often was implied but never spoken outin C++03.

Pure construction semantics was considered as useful as well, soHasConstructordid also exist and would surely be useful as trait as well.

Another example that is often overlooked: This also affects wrapper types likepair,tuple,array that contain potentially more than one type:This is easy to understand if you think ofT1 having a deleted destructorandT2 having a constructor that may throw: Obviously the compiler haspotentially need to use thedestructor ofT1 in theconstructorofstd::pair<T1, T2> to ensure that the core language requirementsare satisfied (All previous fully constructed sub-objects must be destructed).

The core language also honors this fact in [class.copy] p11:

A defaulted copy/move constructor for a classX is defined as deleted (9.6.3[dcl.fct.def.delete])ifX has:
[…]
— any direct or virtual base class or non-static data member of a type with a destructor that is deletedor inaccessible from the defaulted constructor,
[…]

Dave:
This is aboutis_nothrow_constructible in particular. The fact that it isfoiled by not having anoexcept dtor is a defect.

[2012, Kona]

Move to Open.

is_nothrow_constructible is defined in terms ofis_constructible, which is definedby looking at a hypothetical variable and asking whether the variable definition is known not tothrow exceptions. The issue claims that this also examines the type's destructor, given the context,and thus will returnfalse if the destructor can potentially throw. At least oneimplementation (Howard's) does returnfalse if the constructor isnoexcept(true)and the destructor isnoexcept(false). So that's not a strained interpretation.The issue is asking for this to be defined in terms of placementnew, instead of in termsof a temporary object, to make it clearer thatis_nothrow_constructible looks at thenoexcept status of only the constructor, and not the destructor.

Sketch of what the wording would look like:

requireis_constructible, and then also require that a placementnew operationdoes not throw. (Remembering the title of this issue... What does this imply forswap?

If we accept this resolution, do we need any changes toswap?

STL argues: no, because you are already forbidden from passing anything with a throwingdestructor toswap.

Dietmar argues: no, not true. Maybe statically the destructor can conceivably throw for somevalues, but maybe there are some values known not to throw. In that case, it's correct topass those values toswap.

[2017-01-27 Telecon]

Gave the issue a better title

This issue interacts with2827(i)

Ville would like "an evolution group" to take a look at this issue.

[2020-08; LWG reflector]

A poll was taken to close the issue as NAD, but only gained three votes in favour(and one vote against, which was subsequently withdrawn).

[2022-03; LWG reflector]

A poll was taken to close the issue as NAD, with six votes in favour.(and one vote against, subsequently withdrawn).

"Write a paper if you want something else. These traits have well established meaning now.""Minimizing requirements is not as important a concern for standard library concepts as as minimizing the number of concepts.Requirements like 'I need to construct but not destroy an object' are niche enough that we don't need to support them."

[2022-11-30; LWG telecon]

Alisdair intends to write a paper for this.

[2023-05-25; May 2023 mailing]

Alisdair providedP2842R0.

Proposed resolution:


[8]ページ先頭

©2009-2026 Movatter.jp