I\'m trying to check some of my code for strict aliasing violations, but it looks like I\'ve missed something while trying to understand the strict aliasing rule.
Im
My interpretation of the situation:
*( ( unsigned short * )&l ) = 1;
is easier to catch, because the violation is in one line. So it's always caught.
With optimization, the second variation is also caught. After optimization, it's as simple as the first.
Without optimization, -Wstrict-aliasing=1
, which is lazier than the default, catches it. This is because it treats the cast itself as a violation, even without the dereference (delete the dereference and see). This simplistic logic is fast, but leads to false positives.