-Werror
turns all warnings defined by other switches into errors, so you'll have to use -Wall
as well as -Werror
.
g++ -Werror -Wall main.cpp
Moreover, since j
isn't marked static
, there is no guarantee that it won't be used outside of the compilation unit it's defined in, so the compiler can't assume it's unused.