C++ Logo

std-discussion

Advanced search

[basic.life]/8.5 interpretation

From: John Mousseau <jhnmou20_at_[hidden]>
Date: Tue, 8 Sep 2020 19:49:23 +0200
Dear list members,

in draft N4860 <https://isocpp.org/files/papers/N4860.pdf>, which I assume
is close to C++20, the wording of [basic.life]/8 differs from C++17 in that
the notion of "transparently replaceable" was involved. I am wondering
whether condition 8.5 of that paragraph allows for p1 and p2 to be the same
object.

Consider the following most trivial example:

    struct X {int i; float f;};
    X x{3, 3.f};
    new(&x.i) int(5);
    // x.i == 5 without launder? True in C++17.

According to C++17's wording this is surely the case as there is no
const-qualification involved at all. However, in the newest wording, while
conditions (8.1) through (8.4) are fulfilled (for o1 and o2 being the old
and new int respectively), condition (8.5) might be unfulfilled, as neither
are both objects complete, nor are they subobjects of (different) objects
p1 and p2, unless, by [intro.object]/2, the new int becomes a subobject of
x, and when then consider p1 and p2 of [basic.life]/8.5 to be identical. If
we then consider x to be transparently-replaceable by itself, the condition
would be fulfilled. Is that the intended interpretation or is the intention
that the access in my example now requires std::launder even though no
constness is involved?

Sorry in case I am not seeing the obvious and thank you for your time.

Best Regards
John Mousseau

Received on 2020-09-08 12:53:06