【发布时间】:2012-04-07 19:23:00
【问题描述】:
当我添加时
#pragma GCC diagnostic error "-Wreturn-type"
编译器会为每个缺少的return 生成警告,而不是错误。我怎样才能让它把这个特定的警告变成一个错误?
测试代码:
#pragma GCC diagnostic error "-Wreturn-type"
int foo(int x)
{
if (x) return 8;
}
int main(int narg, char* arg[])
{
foo(narg);
}
我试过了
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)
更新:我按照@sastraxi 的建议尝试了-Werror=return-type,但效果相同。
【问题讨论】: