2012-03-23 90 views
2

當我添加GCC:在休息彙編「控制到達非void函數結束」

#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-蘋果darwin10-G ++嘗試 - 4.2.1(GCC)4.2.1(蘋果公司建立5666)(點3)

的i686-蘋果darwin10-LLVM-G ++ - 4.2(GCC)4.2.1(基於蘋果公司建立5658)(LLVM構建2335.6)

更新:我嘗試了@sastraxi建議的-Werror=return-type,但它具有相同的效果。

回答

7

嘗試將-Werror=return-type傳遞給gcc!

+0

這是正確的。但讓它看起來像一個答案,而不是一個問題。 – Nawaz 2012-03-23 08:02:08

+0

只爲你,納瓦茲! :) – sastraxi 2012-03-23 08:03:40

+0

它具有相同的效果 - 一個警告,而不是一個錯誤。 – hamstergene 2012-03-23 08:14:14

相關問題