如何为忘记的返回语句打开 gcc 警告?
它应该在以下情况下警告我:
int foo() {
std::cout << "haha";
}
我知道 -Wall
会打开该警告,但它会启用太多其他警告。
最佳答案
根据 gcc 的 online documentation , -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
似乎可以解决问题:
Warn whenever a function is defined with a return-type that defaults to int. Also warn about any return statement with no return-value in a function whose return-type is not void (falling off the end of the function body is considered returning without a value), and about a return statement with an expression in a function whose return-type is void.
但是,如果打开 -Wall
使您的代码有太多警告,我建议您修复您的代码!
关于c++ - 如何为忘记的返回语句打开 gcc 警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5655181/