I would like to add CXXFLAG to my build systems, which strongly define the entire CXXFLAG . Therefore, each piece of code that demonstrates undefined behavior in a static way must be rejected by the compiler.
For example, reinterpret_cast<A*>(someIntPtr)->aMember does not have any runtime context undefined (a), but int i = bar(); i /= i; int i = bar(); i /= i; can lead to undefined (b) behavior depending on the runtime estimate of bar() (which can return zero).
I expect that (a) the cases will be caught, and not necessarily (b).
source share