4 ms·
This is not strict aliasing as far as I understand. Strict aliasing is about inference of distinctness of pointers. The case here is that an invalidly typed poi
by jstimpfle 4y ago
This is not strict aliasing as far as I understand. Strict aliasing is about inference of distinctness of pointers. The case here is that an invalidly typed pointer is created (a bool pointer pointing to where there is no bool). Not sure what this situation is called in standardese.
- gpderetta 4y agoThe type aliasing rule is also known as the strict aliasing rule, see for example: https://en.cppreference.com/w/c/language/object https://en.cppreference.com/w/c/language/object
- jstimpfle 4y agoAfter skimming this, I still think the strict aliasing rule is used by compiler to avoid re-reads. What you were talking about is probably something else, maybe an "invalid lvalue access" as per your link.
- gpderetta 4y agoFrom cpp reference: "Strict Aliasing: Given an object with effective type T1, using an lvalue expression (typically, dereferencing a pointer) of a different type T2 is undefined behavior, unless [non relevant exceptions omitted]". In this case the expression has type bool and the underlying object has type int, so it is a straightforward strict aliasing violation. With GCC you can compile with -fno-strict-aliasing to ignore this rule. But now you fall afoul of the rule that prevents accessing an invalid representation (i.e. a trap-representation) of an object. This rule is also described in the link I posted before, under the object representation paragraph.
- jstimpfle 4y agook, so in the case above, it's both (if strict aliasing is active). Makes sense now.