Are there any command line options or techniques to make the GCC compiler report errors if the program does not behave in a predictable way according to the C++11 standard?
Asked
Active
Viewed 1,861 times
6
-
3A good start is to compile with `-Wall -Werror`. – erip Feb 01 '16 at 18:58
-
1By "the program", you mean the compiler or the program you are writing? – Maestro Feb 01 '16 at 18:58
-
2GCC has [Undefined Behavior Sanitizer](http://stackoverflow.com/questions/20738232/gcc-4-9-undefined-behavior-sanitizer). – LogicStuff Feb 01 '16 at 18:58
-
3This question isn't _too broad_. It's specific for GCC and asking about the _workings_ of programming tools certainly isn't off-topic! If anything else the question is a dupe of @LogicStuff's link. – πάντα ῥεῖ Feb 01 '16 at 19:04
-
@πάνταῥεῖ! Thank you for editing! – Dániel Sándor Feb 01 '16 at 19:23
1 Answers
7
... to make the compiler to report some errors ...
Yes, there's a number of warnings do detect possible UB, and you can turn warnings into error using the -Werror
option of GCC.
Also as mentioned in @LogicStuff's comment GCC supports the Undefined Behavior Sanitizer.
Though the better tools to detect UB are mostly Static Code Analysis tools, which can detect most of such defects.
You'll have to deal with false positives in any case though, and need to check your code again deeply.