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
[conv.lval] Improve the note about std::nullptr_t case #2372
Conversation
The meaning of "fetched from memory" is vague, and the two uses of term "access" [defns.access] are inappropreate here because - it causes undefined behavior to access an inactive member of a union, based on the rule of out-of-lifetime object [basic.life]: > The program has undefined behavior if: > - the glvalue is used to access the object, or - it implies reading the referenced object of std::nullptr_t, which is defined to be a side effect for volatile-qualified case. [intro.execution] > Reading an object designated by a volatile glvalue, ... are all > side effects, ...
source/expressions.tex
Outdated
Since no value is fetched from memory, | ||
there is no side effect for a volatile access\iref{intro.execution}, and | ||
an inactive member of a union\iref{class.union} may be accessed. | ||
Since the conversion does not read the object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "read" -> "access"?
Do we know what "the object" refers to, here? I'm not seeing an antecedent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with "read" -> "access".
For "the object", I found 3 phrasing to say the same thing:
- "the referenced object" in the previous paragraph.
- "the object to which the glvalue refers" at the bullet of invalid pointer value.
- "the object indicated by the glvalue" at the last bullet.
I choose the second as the most clear one.
Added commit 45edb77.
- "read the object" -> "access the object" The "read" was derived from the rule at [intro.execution], but it didn't fit well here. - "the object" -> "the object to which the glvalue refers" Make it clear what "the object" refers to. cplusplus#2372 (review)
I found a bug report against clang about access on inactive |
Implementations take time to implement DR resolutions. (FWIW, I just fixed this in Clang trunk.) |
Understood. Glad to see the fix. As for how can we say "no value is fetched from memory" or struct S {};
union { int x; S y; } a = {37};
S s = a.y; // No undefined behavior? because member-wise copy (defined at [class.copy.ctor]) for such a class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a (slight) net improvement of the wording in a note. Fine with me.
The meaning of "fetched from memory" is vague, and the two uses of term
"access" [defns.access] are inappropreate here because
union, based on the rule of out-of-lifetime object [basic.life]:
which is defined to be a side effect for volatile-qualified case.
[intro.execution]
The change blindly assumes that "no value is fetched from memory" is
true and rephrases it as "the conversion does not read the object", but
I'm not sure how it is true. In fact, gcc 8.2 emits read instruction for
volatile-qualified case https://godbolt.org/z/uhn72l (clang 7.0.0
doesn't), and both gcc 8.2 and clang 7.0.0 reads a member subobject of
type std::nullptr_t https://godbolt.org/z/fqBU-H.
FYI: The note was added by CWG issue 2140 for C++17.
https://wg21.cmeerw.net/cwg/issue2140
commit 28c12a8