-
Notifications
You must be signed in to change notification settings - Fork 771
[conv.lval] Make note and generalize comment on UB CWG2899 #7051
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
Conversation
"We could consider memcpy to implicitly begin the lifetime of a new bool..."
Unless you show a real example where the situation can happen outside of erroneous values, this change is rejected. When CWG reviewed the wording not too long ago, we could not come up with an example. We believe we have sufficient wording elsewhere so that we cannot otherwise be in a valid situation where we try to read a bool from random garbage bytes. Also, this changes the normative content of the standard (thus can't be an editorial change); I'm not seeing that [defns.access] by itself would somehow cause undefined behavior. |
[cstring.syn] p3 literally says:
I have shown that example. The only reason why that code is UB is because |
If we have another situation where a bad bit pattern can end up in a value representation and we can read from it before hitting undefined behavior earlier, the right fix is to strike the "erroneous value" part of the normative phrasing. That's not editorial, of course. |
I see it as editorial because it is already undefined behavior given that there is no value that can be read by lvalue-to-rvalue conversion in the first place. If the second sentence is redundant and any such case is already UB, it could be deleted (or turned into a note) and it wouldn't change the semantics of the standard or impact any implementation. I guess this is getting too controversial for CWG not to see it though, and I should open a CWG issue about this. |
Even FYI P2624 seemingly wants to eliminate such UB. |
The core issue has been approved. |
The last sentence ([conv.lval] p3.4) is redundant at best, and defective at worst:
It is misleading to single out erroneous values because this happens with any value (or lack thereof) in general. Consider the following example:
We could consider
memcpy
to implicitly begin the lifetime of a newbool
object within the storage ofb
, and becauseb
is transparently replaceable by such an object, this is almost valid. However, because no value ofbool
corresponds to a value representation of0x02
(at least in the Itanium ABI), the behavior is undefined because the lvalue-to-rvalue conversion ofb
reads the value ofb
, but no such value exists.The current wording only mentions erroneous values, and leads the reader to believe that only erroneous values can lead to value representations that don't correspond to any value, but this is not accurate.
To fix this, I've generalized the wording so that it doesn't single out erroneous values anymore, and made it into a note, since it's already UB based on the wording in [defns.access].
At worst, the current wording is defective because it talks about the "result" of the lvalue-to-rvalue conversion, but there cannot possibly be a result if the access is UB already.