Recientemente cometí un error y pasé un puntero en vez de un bool
, y el compilador no me avisó de nada. ¿Hay alguna forma de detectarlo?
Un ejemplo mínimo:
#include <iostream>
void funcion(bool variable);
void funcion(bool variable)
{
std::cout << "En funcion variable= "<< variable <<" \n";
}
int main()
{
int *b = NULL;
funcion(b);
return 0;
}
Compilado con:
g++ ejemplo.c++ -Wall -Wextra -Wdelete-non-virtual-dtor -Wswitch-default -Wshadow -Wsign-promo
-Wctor-dtor-privacy -Wcast-align -Wdisabled-optimization -Wlogical-op -Wmissing-declarations
-Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wredundant-decls -Wstrict-null-sentinel
-Wundef -Wformat=2 -Wunused-macros -Wno-endif-labels -Wstrict-overflow=4 -Warray-bounds=2
-Wold-style-cast -Wconversion -Wunused -Wdouble-promotion -Wformat-overflow=2
-Wno-ignored-attributes -Wattributes -Wunused-but-set-variable -Wduplicated-branches
-Wduplicated-cond -Wtrampolines -Wfloat-equal -Wshadow=global -Wunsafe-loop-optimizations
-Wpointer-arith -Wcast-qual -Wdangling-else -Wfloat-conversion -Wlogical-op -Wredundant-decls
-Wsuggest-attribute=noreturn -Wsuggest-attribute=format -Wsuggest-attribute=cold
-Wsuggest-attribute=malloc -Wsuggest-attribute=const
Esto compila normalmente sin error ni advertencia.