Shafik Yaghmour

Compiler Engineer at Intel. This is a personal blog. The opinions stated here are my own, not those of my company.

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:

and