Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ GCC:在“上中断编译”;控制达到非无效函数的末尾“;_C++_C_Gcc_G++ - Fatal编程技术网

C++ GCC:在“上中断编译”;控制达到非无效函数的末尾“;

C++ GCC:在“上中断编译”;控制达到非无效函数的末尾“;,c++,c,gcc,g++,C++,C,Gcc,G++,当我加上 #pragma GCC diagnostic error "-Wreturn-type" 编译器为每个缺少的返回生成警告,而不是错误。我怎样才能使它把这个特别的警告变成一个错误呢 测试代码: #pragma GCC diagnostic error "-Wreturn-type" int foo(int x) { if (x) return 8; } int main(int narg, char* arg[]) { foo

当我加上

#pragma GCC diagnostic error "-Wreturn-type"
编译器为每个缺少的
返回生成警告,而不是错误。我怎样才能使它把这个特别的警告变成一个错误呢

测试代码:

#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)(dot 3)

i686-apple-darwin10-llvm-g++-4.2(GCC)4.2.1(基于apple Inc.build 5658)(llvm build 2335.6)


更新:我尝试了@sastraxi建议的
-Werror=返回类型
,但效果相同。

尝试将
-Werror=返回类型
传递给gcc

这是正确的。但是,让它看起来像一个答案,而不是一个问题。当运行g++或gcc 4.5.2-8ubuntu4时,即使不添加它,我也会得到一个错误。苹果的gcc是不同的和旧的,我想你就是不能。
-Werror=
是一个新特性(在4.4版本中添加)这是我的错,我没有仔细阅读这个问题,看清楚它是4.4版本之前的。如果需要,可以直接使用
-Werror
将所有警告转化为错误。