Full name of submitter (unless configured in github; will be published with the issue): Jiang An
Reference (section label): [expr.const]
Link to reflector thread (if any):
Issue description:
[expr.const] p9.2 states that the lifetime of mutable subobjects is not considered to start within the hypothetical expression when determining whether an object has constant destruction. But [expr.const] p5.17 seemingly states that a destruction call of such a member would make the hypothetical expression not a core constant expression, which may in turn make the complete object not have constant destruction.
Given the following example:
struct Foo {};
struct Bar {
mutable Foo f;
};
constexpr Bar b{};
when determining whether b has constant destruction, the hypothetical expression E need to call the destructor for b.f, and the lifetime of b.f is not considered to start within E. As a result, [expr.const] p9 and [expr.const] p5.17 would make b not have constant destruction, and thus make the program ill-formed.
The current wording is introducing incompatibility with C++17 (where trivial destructibility was used). Implementations accept this example in their C++20 modes (Godbolt link).
Perhaps we should exclude [expr.const] p5.17 when determining whether the hypothetical expression is a core constant expression.
Full name of submitter (unless configured in github; will be published with the issue): Jiang An
Reference (section label): [expr.const]
Link to reflector thread (if any):
Issue description:
[expr.const] p9.2 states that the lifetime of mutable subobjects is not considered to start within the hypothetical expression when determining whether an object has constant destruction. But [expr.const] p5.17 seemingly states that a destruction call of such a member would make the hypothetical expression not a core constant expression, which may in turn make the complete object not have constant destruction.
Given the following example:
when determining whether
b
has constant destruction, the hypothetical expression E need to call the destructor forb.f
, and the lifetime ofb.f
is not considered to start within E. As a result, [expr.const] p9 and [expr.const] p5.17 would makeb
not have constant destruction, and thus make the program ill-formed.The current wording is introducing incompatibility with C++17 (where trivial destructibility was used). Implementations accept this example in their C++20 modes (Godbolt link).
Perhaps we should exclude [expr.const] p5.17 when determining whether the hypothetical expression is a core constant expression.
Suggested resolution: