I would like to add a CXXFLAG
to my build systems that force the entire code-base to be well-defined. So every piece of code that exhibits undefined behaviour in a static fashion, should be refused by the compiler.
For instance reinterpret_cast<A*>(someIntPtr)->aMember
is without any runtime context undefined (a), while int i = bar(); i /= i;
could result in undefined behaviour (b) depending on the runtime evaluation of bar()
(which could return zero).
I only expect the (a) cases to be caught, not necessarily the (b) cases.
I'm not sure that your goal is computationally feasible.
However, you'll get moderately close with -Wall -Wextra -Werror
; look at the other warning options to see what else you want to enable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With