簡體   English   中英

海灣合作委員會:關於“控制到非空函數結束”的中斷編譯

[英]GCC: Break compilation on “control reaches end of non-void function”

當我添加

#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)

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM