In gcc-4.9 changes it says:
UndefinedBehaviorSanitizer (ubsan), a fast undefined behavior detector, has been added and can be enabled via -fsanitize=undefined. Various computations will be instrumented to detect undefined behavior at runtime. UndefinedBehaviorSanitizer is currently available for the C and C++ languages.
I looked at this question (A C++ implementation that detects undefined behavior?) but it seems fairly outdated.
This link (http://gcc.gnu.org/ml/gcc-patches/2013-06/msg00264.html) has some information on it, but it's several months old.
This is an attempt to add the Undefined Behavior Sanitizer to GCC. Note that it's very alpha version; so far it doesn't do that much, at the moment it should handle division by zero cases, INT_MIN / -1, and various shift cases (shifting by a negative value, shifting when second operand is >= than TYPE_PRECISION (first_operand) and suchlike. (On integer types, so far.)
From what I've read it's being ported to gcc
from LLVM
.
I've tried it with (5 / 0)
and the only difference seems to be this output:
main.cpp:5:19: runtime error: division by zero
Does anyone have any more information on it or what features it has?
See Question&Answers more detail:os