Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[basic.life]/8.5 breaks subobject replacement depending on interpretation #4167

Closed
jmcasc opened this issue Sep 9, 2020 · 2 comments
Closed

Comments

@jmcasc
Copy link

jmcasc commented Sep 9, 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:

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.

@jmcasc 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
@jmcasc jmcasc closed this as completed Dec 18, 2020
@tkoeppe
Copy link
Contributor

tkoeppe commented Dec 18, 2020

Please note that this issue tracker is for editorial issues only (e.g. typos, bad whitespace, etc.), not for technical issues. See also https://github.com/cplusplus/draft/wiki/How-to-tell-if-an-issue-is-editorial.

@jmcasc
Copy link
Author

jmcasc commented Dec 18, 2020

My apologies. I realised this and intended to delete it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants