Re:The Strict Aliasing Situation Is Pretty Bad
by mcguire on Tuesday March 15, 2016 @04:00PM
(#11292521)
Are you sure about 'illegal' there? Is any compiler going to complain?
All the compilers I have used will cheerfully reference unallocated memory; I thought the behavior was undefined.
Re:The Strict Aliasing Situation Is Pretty Bad
by haberman on Tuesday March 15, 2016 @04:50PM
(#11292875)
When I say "illegal" here, read "undefined behavior." Since undefined behavior is so potentially disastrous, I consider it basically illegal.
Re:The Strict Aliasing Situation Is Pretty Bad
by mcguire on Thursday March 17, 2016 @12:05PM
(#11305233)
To my mind, 'illegal' means that the compiler will complain. In this case, I don't even see weird, scary UB; this is just a case of the standard being completely unable to say anything about what will happen.
After spending too much of my life chasing these bugs, here the compiler will do exactly what you told it to, which probably means making your day miserable.
But if the object isn't actually a Derived, you can't cast to pointer-to-Derived: