2010-08-15 88 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