You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am wondering whether condition 8.5 of [basic.life]/8 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};
int& ri = x.i;
new(&x.i) int(5);
bool b = x.i == 5; // 1) Well-defined and true without launder in C++17
bool b2 = ri == 5; // 2) Well-defined and true without launder 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 which introduced the relation "transparently replaceable" this might not be the case. 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 we 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? Otherwise, it seems like it might break the old behavior under a strict interpretation that doesn't allow p1 and p2 to be the same and the access in my example might then require std::launder even though no const-ness is involved.
I am mainly referring to line 2). In the case of 1) the fact that x still refers to the same X object might make the paragraph irrelevant if the .member notation strictly refers to the current i (i.e. the new int) of x, but I am unsure.
Apologies in case I am overlooking something obvious.
The text was updated successfully, but these errors were encountered:
jmcasc
changed the title
[basic.life]/8.5 allows p1 and p2 to be identical?
[basic.life]/8.5 breaks subobject replacement depending on interpretation
Sep 10, 2020
I am wondering whether condition 8.5 of [basic.life]/8 allows for p1 and p2 to be the same object.
Consider the following most trivial example:
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 which introduced the relation "transparently replaceable" this might not be the case. 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 we 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? Otherwise, it seems like it might break the old behavior under a strict interpretation that doesn't allow p1 and p2 to be the same and the access in my example might then require std::launder even though no const-ness is involved.
I am mainly referring to line 2). In the case of 1) the fact that x still refers to the same X object might make the paragraph irrelevant if the .member notation strictly refers to the current i (i.e. the new int) of x, but I am unsure.
Apologies in case I am overlooking something obvious.
The text was updated successfully, but these errors were encountered: