2010-08-15 84 views
10

如何为GCC下缺少的返回语句生成错误?关于缺少返回语句的错误

cpfsfuse.c:184: warning: no return statement in function returning non-void 

我能为隐函数的声明(-Werror-implicit-function-declaration)返回错误,我知道一个-Werror=开关的,但我不能找到一个合适的警告提升至错误状态。

我怎样才能做到这一点?

回答

17

您应该可以使用-fdiagnostics-show-option选项来显示Werror=开关的正确标志。从this博客文章摘自:

% gcc -x c -Wall -Wextra -fdiagnostics-show-option -c -o /dev/null - <<EOF 
int foo() { 
} 
EOF 
<stdin> In function ‘foo’: 
<stdin>:2: warning: control reaches end of non-void function [-Wreturn-type] 

事实上,它看起来像return-type标志可能是你想要的。

+1

辉煌的先生! – 2010-08-15 11:30:19