[英]How to turn on gcc warnings for a forgotten return statement?
如何为遗忘的退货声明打开gcc警告?
它应该在以下情况下警告我:
int foo() {
std::cout << "haha";
}
我知道-Wall
会发出警告,但它会发出太多其他警告。
根据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-type
似乎可以解决问题:
每当使用默认为int的返回类型定义函数时发出警告。 还要警告任何return语句没有返回值,返回类型不是void的函数(从函数体的末尾掉落被认为是没有值返回) ,以及一个函数中带有表达式的return语句return-type无效。
但是,如果启用-Wall
会使您的代码有太多警告,我建议修复您的代码!
总是使用:
gcc -g -ans--pedantic -Wall -o
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.