BIV BIV - 1 month ago 9
C++ Question

force c++ compiler to check returning value

In this example will be called deconstructor of nonexisting object. G++ version 5.3, compiling with -Werror .

vector<vector<float>> segfault()
{

}

int main()
{
segfault();
return 0;
}

Answer

Both gcc and clang have the option -Wreturn-type.
It is turned on implicitly when using -Wall.
To make ensue it is a compiler error, use -Werror=return-type.