I recently made a very minor but very hard to find mistake in my code, here's an MCVE:
#include<iostream>
int foo(){
return false;
}
int main(){
int x = foo();
std::cout << x;
return 0;
}
As you can see, here the function foo returns false, which - as far as I can tell - gets auto-promoted to int and stored into x.
However, this was a logical mistake on my end, and, surprisingly, was not caught both while compilation and in CLion. gmm is my compilation flag. It is supposed to catch memory leaks, runtime errors (mostly all usual undefined behavior) as well as it internally calls gww which has the most common warnings enabled.
Moreover, in CLion, CLang-tidy and Clang's own inspector almost always catch all the common mistakes in my code.
I do a lot of competitive programming, and this mistake recently happened live in contest. I would rather want to avoid it. I have attached my compilation flag below. I have all possible C/C++ inspections enabled in CLion Settings. Is it possible to adjust them, add a new setting, or do anything - during either compilation or in CLion or both - to be able to catch this issue at compile time?
alias gww='g++ -Wall -Weffc++ -pedantic \
-pedantic-errors -Wextra -Wcast-align \
-Wcast-qual -Wconversion \
-Wdisabled-optimization \
-Wfloat-equal -Wformat=2 \
-Wformat-nonliteral -Wformat-security \
-Wformat-y2k \
-Wimport -Winit-self -Winline \
-Winvalid-pch \
-Wmissing-field-initializers -Wmissing-format-attribute \
-Wmissing-include-dirs -Wmissing-noreturn \
-Wpacked -Wpointer-arith \
-Wredundant-decls \
-Wshadow -Wstack-protector \
-Wstrict-aliasing=2 -Wswitch-default \
-Wswitch-enum \
-Wunreachable-code -Wunused \
-Wunused-but-set-variable \
-Wunused-parameter \
-Wvariadic-macros \
-Wwrite-strings'
alias gmm="gww -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG"