缺少return语句时出错

Mat*_*ner 11 gcc compiler-errors return

如何在GCC下为缺少的return语句生成错误?

cpfsfuse.c:184: warning: no return statement in function returning non-void
Run Code Online (Sandbox Code Playgroud)

我能够为隐式函数声明(-Werror-implicit-function-declaration)返回错误,并且我知道一个-Werror=开关,但是我找不到适当的警告来提升错误状态.

我怎样才能做到这一点?

Ste*_*hen 18

您应该能够使用该-fdiagnostics-show-option选项显示Werror=交换机的正确标志.摘自博文:

% 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]
Run Code Online (Sandbox Code Playgroud)

实际上,看起来return-type旗帜可能是你想要的旗帜.