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

RU007 [basic.life].8.3 Relax pointer value / aliasing rules #7

Closed
wg21bot opened this issue Oct 23, 2019 · 5 comments · Fixed by cplusplus/draft#3481
Closed

RU007 [basic.life].8.3 Relax pointer value / aliasing rules #7

wg21bot opened this issue Oct 23, 2019 · 5 comments · Fixed by cplusplus/draft#3481
Labels
Projects
Milestone

Comments

@wg21bot
Copy link
Collaborator

wg21bot commented Oct 23, 2019

In many cases it is impossible to use a pointer returned from placement new or std::launder (for example in std::vector, std::variant, std::optional, std::uninitialized_+std::destroy).
Because of that issue all the standard libraries have undefined behaviors in widely used types. The only way to fix that issue is to adjust the lifetime rules to auto-launder the placement new.
Dropping the “const“ and “reference” requirement from paragraph 8 [basic.life] removes UB from std::vector and std::optional. Additional removing of the “potentially-overlapping” requirement removes UB from std::variant.

Proposed change:
Apply the following changes to the [basic.life] paragraph 8 bullet 3:
– the type of the original object is not const-qualified, and, if a class type, does not contain any non-static data member whose type is const-qualified or a reference type, and

Optionally remove the to the bullet 4 from [basic.life] paragraph 8:
neither the original object nor the new object is a potentially-overlapping subobject ([intro.object]).

@wg21bot wg21bot added the EWG Evolution label Oct 23, 2019
@jfbastien jfbastien added SG12 Undefined behavior and removed EWG Evolution labels Oct 24, 2019
@jfbastien
Copy link
Collaborator

jfbastien commented Oct 27, 2019

From #41 (closed as duplicate):

The restriction on automatically referring to the new object when a class type contains a non-static data member of const-qualified or reference type renders use of the pointer returned by data() of a std::vector of such class types unsafe without applying std::launder. In particular, if a pointer returned by data() on a one-element vector of a class type that is subject to the restriction is stored and then followed by a pop_back() and a call to push_back, then the stored pointer would not be usable to access the new element without applying launder. The need to apply launder is not currently indicated by the library wording and is presumably unwanted.

Proposed change:
In the bullet, strike:
• the type of the original object is not const-qualified, and, if a class type, does not contain any non-static data member whose type is const-qualified or a reference type, and
Remove, from subclause 6.6.2 [intro.object] paragraph 2, the note beginning with “[i]f the subobject contains a reference member or [ … ]” and the associated example.

Please send to EWG with SG12 guidance, if appropriate.

@jfbastien jfbastien added EWG Evolution CWG Core and removed EWG Evolution labels Nov 6, 2019
@jfbastien
Copy link
Collaborator

CWG to recommend a fix, send it back to SG12, trickle back to EWG, then back to CWG.

@jensmaurer jensmaurer added this to TODO in CWG Nov 6, 2019
@jensmaurer
Copy link
Member

CWG in Belfast: See wiki notes for RU007. Summary: Leave p8.4 alone; change p8.3 to read "the original object is neither a complete object that is const-qualified nor a subobject of such an object".

@jensmaurer jensmaurer moved this from TODO to Deferred for other group input in CWG Nov 6, 2019
@jensmaurer jensmaurer added EWG Evolution and removed CWG Core labels Nov 6, 2019
@jfbastien
Copy link
Collaborator

EWG on Thursday: http://wiki.edg.com/bin/view/Wg21belfast/RU007

Accept RU007 with modification. Update basic.life p8.3 to read “the original object is neither a complete object that is const-qualified nor a subobject of such an object.

SF F N A SA
2 13 0 0 0

@jfbastien jfbastien added CWG Core and removed EWG Evolution labels Nov 7, 2019
@jensmaurer jensmaurer moved this from Deferred for other group input to TODO in CWG Nov 7, 2019
@jensmaurer jensmaurer moved this from TODO to Drafting in CWG Nov 8, 2019
@jensmaurer jensmaurer removed the SG12 Undefined behavior label Nov 8, 2019
@jensmaurer jensmaurer moved this from Drafting to TODO in CWG Nov 8, 2019
@jensmaurer jensmaurer moved this from TODO to Accepted in CWG Nov 8, 2019
@jensmaurer
Copy link
Member

jensmaurer commented Nov 8, 2019

CWG in Belfast: Accepted with modification. See paper P1971R0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
CWG
Accepted
Development

Successfully merging a pull request may close this issue.

3 participants