On 11/25/2015 10:52 PM, Andrey Semashev wrote:
On Wed, Nov 25, 2015 at 7:25 PM, Agustín K-ballo Bergé
wrote: On 11/25/2015 12:46 PM, Andrey Semashev wrote:
On 2015-11-25 18:32, Alexander Lauser wrote:
http://en.cppreference.com/w/cpp/language/union have an example that explicitly states what Gavin claimed. Not sure about the reliability of that site, though.
That sounds like self contradiction to me. The page says it's well defined to examine the common subsequence of standard-layout union members but at the same time it's UB to read from them. What's the difference?
The wording is convoluted, maybe it becomes clearer with some examples.
I see, thank you for the clarification. IMHO, the standard should just follow C11 semantics and say it more clearly.
That's unlikely to happen, C has *vastly* weaker aliasing rules than C++, to the point that several C implementations choose to follow the C++ rules instead. You'd be asking for the opposite to happen.
Regarding the original topic and the proposed Boost.Config macro for detection of this compiler feature, I'm still not sure we need it, although now I'm not as strongly convinced.
As for the original topic, I am certain that having the proposed macro would be a mistake. Don't try to fool a language/compiler smarter than you, or you will end up getting what you asked for (UB) sooner or later. If you have types whose values are comprised by just a set of bits, and you'd wish to operate on said value representation, then do so by using the tools for operating on the value representation of such trivial types. Type punning via unions is not that tool. Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com