Dániel Sándor
Dániel Sándor

Reputation: 1294

Are there any techniques to detect undefined behaviour with GCC?

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?

Upvotes: 7

Views: 2582

Answers (1)

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

... 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.

Upvotes: 7

Related Questions