Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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 - Fatal编程技术网

C++ 如何为忘记的返回语句打开gcc警告?

C++ 如何为忘记的返回语句打开gcc警告?,c++,c,gcc,C++,C,Gcc,如何为忘记的返回语句打开gcc警告 它应该在以下情况下警告我: int foo() { std::cout << "haha"; } intfoo(){ 标准::cout根据gcc,-Wall打开: -Waddress -Warray-bounds (only with -O2) -Wc++0x-compat -Wchar-subscripts -Wenum-compare (in C/Objc; t

如何为忘记的返回语句打开gcc警告

它应该在以下情况下警告我:

int foo() {
  std::cout << "haha";
}
intfoo(){
标准::cout根据gcc,
-Wall
打开:

      -Waddress   
      -Warray-bounds (only with -O2)  
      -Wc++0x-compat  
      -Wchar-subscripts  
      -Wenum-compare (in C/Objc; this is on by default in C++) 
      -Wimplicit-int (C and Objective-C only) 
      -Wimplicit-function-declaration (C and Objective-C only) 
      -Wcomment  
      -Wformat   
      -Wmain (only for C/ObjC and unless -ffreestanding)  
      -Wmissing-braces  
      -Wnonnull  
      -Wparentheses  
      -Wpointer-sign  
      -Wreorder   
      -Wreturn-type  
      -Wsequence-point  
      -Wsign-compare (only in C++)  
      -Wstrict-aliasing  
      -Wstrict-overflow=1  
      -Wswitch  
      -Wtrigraphs  
      -Wuninitialized  
      -Wunknown-pragmas  
      -Wunused-function  
      -Wunused-label     
      -Wunused-value     
      -Wunused-variable  
      -Wvolatile-register-var 
其中,
-Wreturn类型
似乎可以实现以下目的:

每当使用默认为int的返回类型定义函数时发出警告。对于返回类型不是void的函数中没有返回值的任何返回语句也发出警告(从函数体末尾脱落视为没有返回值),以及关于返回类型为void的函数中带有表达式的返回语句

但是,如果打开
-Wall
会使代码出现太多警告,我建议您修复代码!

始终使用:


gcc-g-ansi-pedantic-Wall-o

您是否尝试过-Wextra/-ansi/-pedantic?
-Wall
启用太多其他警告?这是第一次。如果您启用了太多的-Wall,另一种选择是切换不符合您的编码风格的特定警告。尽管我很想知道您有哪些警告不要就代码中的问题向您提供有价值的反馈。@Jens Gustedt:另一种可能是重写代码以减少警告的数量。启用大量错误检查但没有警告的代码是非常有用的。保持这种方式比以这种方式获取要容易得多。