当我添加
#pragma GCC diagnostic error "-Wreturn-type"
Run Code Online (Sandbox Code Playgroud)
编译器产生警告,而不是每个缺失的错误return.如何将此特定警告变为错误?
测试代码:
#pragma GCC diagnostic error "-Wreturn-type"
int foo(int x)
{
if (x) return 8;
}
int main(int narg, char* arg[])
{
foo(narg);
}
Run Code Online (Sandbox Code Playgroud)
我试过了
i686-apple-darwin10-g ++ - 4.2.1(GCC)4.2.1(Apple Inc. build 5666)(第3点)
i686-apple-darwin10-llvm-g ++ - 4.2(GCC)4.2.1(基于Apple Inc. build 5658)(LLVM build 2335.6)
更新:我-Werror=return-type按照@sastraxi的建议尝试过,但效果相同.
尝试传递-Werror=return-type给gcc!