https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120806

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The implementation in libstdc++ is the one called "friendly" in the P1132R8
paper. This was clearly intended to be allowed:

"Teams eager to squeeze out performance realize they can only do this by
relying on type-punning shenanigans to extract the actual value out of
unique_ptr: this is expressly undefined behavior. However, if an implementation
of out_ptr could be friended or shipped by the standard library, it can be
implemented without performance penalty."

"it would be much more prudent to allow both standard library vendors and users
to be able to achieve this performance without hacks, tricks, and other
I-promise-it-works-I-swear pledges."

It seems very clear to me that the intended design was to allow implementations
to perform these optimizations, and if the wording in the standard doesn't
allow it, that's a defect in the standard.

Reply via email to