You do not need a Sanitizer to catch this error. The compiler can detect this error at compile time (sanitizers and valgrind work at runtime). In fact, all GCC Clang and ICC will give a warning for this code if you enable warnings. This particular warning is controlled by the -Wuninitialized flag. In general, it is good practice to always use a high level of warning. I would recommend the following combination of warning flags, especially when learning a language:
-Wall -Wextra -pedantic
If you receive false positives, only after carefully checking that they are really false, you can turn off certain warnings. There is no reason not to use warning flags. Some projects use the -Werror flag, turning all warnings into errors.
source share