A. is a valid aliasing. This is covered in [basic.lval]p11:
If a program attempts to access the stored value of an object through a glvalue of other than one of the following types the behavior is undefined:55
- (11.1) the dynamic type of the object,
- (11.2) a cv-qualified version of the dynamic type of the object,
- (11.3) a type similar (as defined in [conv.qual]) to the dynamic type of the object,
- (11.4) a type that is the signed or unsigned type corresponding to the dynamic type of the object,
- (11.5) a type that is the signed or unsigned type corresponding to a cv-qualified version of the dynamic type of the object,
- (11.6) an aggregate or union type that includes one of the aforementioned types among its elements or non-static data members (including, recursively, an element or non-static data member of a subaggregate or contained union),
- (11.7) a type that is a (possibly cv-qualified) base class type of the dynamic type of the object,
- (11.8) a char, unsigned char, or std::byte type.
Footnote 55 says:
The intent of this list is to specify those circumstances in which an object may or may not be aliased.
A. is allow by [basic.lval]p11.4
B. is not allowed by any of the bullets
C. might be surprise and diff than C, only char, unsigned char are valid for aliasing see [/basic.lval]p11.8
Also worth checking out my Stack Overflow answer to “What is the strict aliasing rule?”
Some replies to this poll that are worth pointing out:
Extra credit question, only for the truly motivated student: does C actually define "character type" anywhere, and if so, where?
— Steve Canon (@stephentyrone) June 22, 2018
and
I liked your use of F for an option lettering ;-)
— Shafik Yaghmour (@shafikyaghmour) June 22, 2018
We should have a simple way to treating on object like a bag of bits, I think bit_cast gets us partly there.
After seeing how pre ANSI C typed punned https://t.co/aAwP7Yp2UF it does have appeal in its simplicity.