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
[out.ptr.t][inout.ptr.t] The notes for operator void**
might suggest violation of the strict aliasing rule
#4701
Comments
The TBAA violation was known when the paper was approved by LWG. @jwakely , do you think there is anything we can do to this note to make it palatable? |
I think this is why we used "can be" rather than "is" - it can be viable on non-TBAA implementations. For some implementations it's not a viable implementation strategy, whether because of TBAA or something else (e.g., |
The main motivation for that member is to interoperate with APIs doing disgusting aliasing violations. The motivating examples in the paper involve aliasing violations, but that doesn't happen inside the standard library. If users choose to pass the |
We intentionally worded this to make the behavior well-defined even for what would otherwise have been disgusting aliasing violations though - that's why we didn't just specify this as returning the result of |
Can we add "for some compilers" to indicate that such strategy is not always viable? |
We tend to avoid the term "compiler" in the standard; some of the existing uses would benefit from replacement by "implementation" or similar. |
The suggested implementation strategy can make the stored
Pointer
member subobject modified via avoid*
lvalue, which violates the strict aliasing rule ([basic.lval]/11), and might result in miscompilation on compilers that make use of TBAA.A
std::byte
array member of appropriate size and alignment is suitable for the required type punning due to implicit object creation (the destructor can readp
bystd::bit_cast
if the such strategy is used).As the strategy using a byte array may be too delicate for a note, can we just remove the notes, or replace the wording with a less detailed one?
(E.g. Recommended practice: If possible, implementations should use no additional storage with respect to that for
p
in order to support both conversion functions.)The text was updated successfully, but these errors were encountered: