C++ 如何打开(字面意思)所有 GCC 的警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11714827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to turn on (literally) ALL of GCC's warnings?
提问by user541686
I would like to enable -- literally -- ALLof the warnings that GCC has. (You'd think it would be easy...)
我想启用 - 字面意思 - GCC 的所有警告。(你会认为这很容易......)
You'd think
-Wall
might do the trick, but nope! Still need-Wextra
.You'd think
-Wextra
might do the trick, but nope! Not all of the warnings listed here(for example,-Wshadow
) are enabled by this. And I still have no idea if this list is comprehensive.
你会认为
-Wall
可能会成功,但不是!还是需要-Wextra
。你会认为
-Wextra
可能会成功,但不是!并非此处列出的所有警告(例如,-Wshadow
)都由此启用。我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) allthe warnings it has?
我如何告诉 GCC 启用(没有 if、and 或 but !)它有的所有警告?
采纳答案by Jonathan Wakely
You can't.
你不能。
The manual for GCC 4.4.0 is only comprehensive for that version, but it does list all the possible warnings for 4.4.0. They're not all on the page you link to though, for instance some language-specific options are on the pages for C++ options or Obj-C options. To find them all you're better off looking at the Options Summary
GCC 4.4.0 的手册仅针对该版本进行了全面介绍,但它确实列出了 4.4.0 的所有可能警告。但是,它们并不都在您链接到的页面上,例如,某些特定于语言的选项位于 C++ 选项或 Obj-C 选项的页面上。要找到所有这些,您最好查看选项摘要
Turning on everythingwould include -Wdouble-promotion
which is only relevant on CPUs with a 32-bit single-precision floating-point unit which implements float
in hardware, but emulates double
in software. Doing calculations as double
would use the software emulation and be slower. That's relevant for some embedded CPUs, but completely irrelevant for modern desktop CPUs with hardware support for 64-bit floating-point.
打开所有内容将包括-Wdouble-promotion
仅与具有 32 位单精度浮点单元的 CPU 相关的内容,该单元float
在硬件中实现,但double
在软件中进行模拟。像double
使用软件仿真一样进行计算并且速度较慢。这与某些嵌入式 CPU 相关,但与具有 64 位浮点硬件支持的现代桌面 CPU 完全无关。
Another warning that's not usually useful is -Wtraditional
, which warns about perfectly well formed code that has a different meaning (or doesn't work) in traditional C, e.g. "string " "concatenation"
, or ISO C function definitions! Do you really care about compatibility with 30 year old compilers? Do you really want a warning for writing int inc(int i) { return i+1; }
?
另一个通常没有用的-Wtraditional
警告是,它警告格式良好的代码在传统 C 中具有不同的含义(或不起作用),例如"string " "concatenation"
,或 ISO C 函数定义!你真的关心与 30 岁的编译器的兼容性吗?你真的想要一个写作警告int inc(int i) { return i+1; }
吗?
I think -Weffc++
is too noisy to be useful, it's based on the outdated first edition of Effective C++and warns about constructs which are perfectly valid C++ (and for which the guidelines changed in later editions of the book.) I don't want to be warned that I haven't initialized a std::string
member in my constructor; it has a default constructor that does exactly what I want, why should I write m_str()
to call it? The -Weffc++
warnings that would be helpful are too difficult for the compiler to detect accurately (giving false negatives), and the ones that aren't useful, such as initializing all members explicitly, just produce too much noise, giving false positives.
我认为-Weffc++
它太嘈杂而无用,它基于过时的Effective C++第一版,并警告完全有效的 C++ 构造(并且在本书的后续版本中更改了指南。)我不想成为警告我没有std::string
在构造函数中初始化成员;它有一个默认构造函数,完全符合我的要求,我为什么要写信m_str()
来调用它?-Weffc++
有用的警告对于编译器来说太难准确检测(给出误报),而那些没有用的警告,例如显式初始化所有成员,只会产生过多的噪音,从而导致误报。
Luc Danton provided a great exampleof useless warnings from -Waggregate-return
that almost certainly never makes sense for C++ code.
Luc Danton 提供了一个很好的无用警告示例,-Waggregate-return
它几乎肯定对 C++ 代码毫无意义。
i.e. you don't really want allwarnings, you just think you do.
即你并不真的想要所有的警告,你只是认为你想要。
Go through the manual, read about them, decide which you might want to enable, try them. Reading your compiler's manual is a Good ThingTManyway, taking a short cut and enabling warnings you don't understand is not a very good idea, especially if it's to avoid having to RTFM.
通读手册,阅读它们,决定您可能想要启用哪些,尝试它们。读你的编译器的手册是一件好事TM反正抄近路,使您不明白的警告是不是一个很好的主意,尤其是如果它以避免对RTFM。
任何只是打开一切的人都可能这样做是因为他们一无所知,因为或者一个尖头发的老板说“没有警告”。
Edit:See also -Wall-all to enable all warningswhich is closed as WONTFIX.
编辑:另请参阅-Wall-all 以启用作为 WONTFIX 关闭的所有警告。
Edit 2:in response to DevSolar's complaint about makefiles needing to use different warnings depending on compiler version, if -Wall -Wextra
isn't suitable then it's not difficult to use compiler-specific and version-specific CFLAGS:
编辑 2:为了回应 DevSolar 关于需要根据编译器版本使用不同警告的 makefile 的抱怨,如果-Wall -Wextra
不合适,那么使用特定于编译器和特定于版本的 CFLAGS 并不困难:
compiler_name := $(notdir $(CC))
ifeq ($(compiler_name),gcc)
compiler_version := $(basename $(shell $(CC) -dumpversion))
endif
ifeq ($(compile_name),clang)
compiler_version := $(shell $(CC) --version | awk 'NR==1{print $}')
endif
# ...
wflags.gcc.base := -Wall -Wextra
wflags.gcc.4.7 := -Wzero-as-null-pointer-constant
wflags.gcc.4.8 := $(wflags.gcc.4.7)
wflags.clang.base := -Wall -Wextra
wflags.clang.3.2 := -Weverything
CFLAGS += $(wflags.$(compiler_name).base) $(wflags.$(compiler_name).$(compiler_version))
回答by Haatschii
I would agree with the previous answers that it is probably not beneficial to enable literally all warnings, however GCC does provide a reasonably convenient way to achieve this. The command
我同意之前的答案,即启用字面上的所有警告可能没有好处,但是 GCC 确实提供了一种相当方便的方法来实现这一点。命令
gcc -Q --help=warning
provides a list of all supported warning options with information on whether they are active. This can by the way be used to find out which options are (not) enabled by e.g. -Wall
and -Wextra
提供所有受支持警告选项的列表,以及有关它们是否处于活动状态的信息。这可以顺便用来找出哪些选项是(不)由 eg-Wall
和-Wextra
gcc -Wall -Wextra -Q --help=warning
To enable all the warnings you can use some regex to extract the command line parameters
要启用所有警告,您可以使用一些正则表达式来提取命令行参数
gcc -Q --help=warning | sed -e 's/^\s*\(\-\S*\)\s*\[\w*\]/ /gp;d' | tr -d '\n'
For my current GCC this gives:
对于我目前的 GCC,这给出了:
-Wabi -Wabi-tag -Waddress -Waggregate-return -Waggressive-loop-optimizations -Waliasing -Walign-commons -Wampersand -Warray-bounds -Warray-temporaries -Wassign-intercept -Wattributes -Wbad-function-cast -Wbool-compare -Wbuiltin-macro-redefined -Wc++-compat -Wc++0x-compat -Wc++14-compat -Wc-binding-type -Wc90-c99-compat -Wc99-c11-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wcharacter-truncation -Wchkp -Wclobbered -Wcomment -Wcompare-reals -Wconditionally-supported -Wconversion -Wconversion-extra -Wconversion-null -Wcoverage-mismatch -Wcpp -Wctor-dtor-privacy -Wdate-time -Wdeclaration-after-statement -Wdelete-incomplete -Wdelete-non-virtual-dtor -Wdeprecated -Wdeprecated-declarations -Wdesignated-init -Wdisabled-optimization -Wdiscarded-array-qualifiers -Wdiscarded-qualifiers -Wdiv-by-zero -Wdouble-promotion -Weffc++ -Wempty-body -Wendif-labels -Wenum-compare -Wextra -Wfloat-equal -Wformat-contains-nul -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat-zero-length -Wfree-nonheap-object -Wfunction-elimination -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wimplicit-interface -Wimplicit-procedure -Wincompatible-pointer-types -Winherited-variadic-ctor -Winit-self -Winline -Wint-conversion -Wint-to-pointer-cast -Wintrinsic-shadow -Wintrinsics-std -Winvalid-memory-model -Winvalid-offsetof -Winvalid-pch -Wjump-misses-init -Wline-truncation -Wliteral-suffix -Wlogical-not-parentheses -Wlogical-op -Wlong-long -Wmain -Wmaybe-uninitialized -Wmemset-transposed-args -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes -Wmultichar -Wnarrowing -Wnested-externs -Wnoexcept -Wnon-template-friend -Wnon-virtual-dtor -Wnonnull -Wodr -Wold-style-cast -Wold-style-declaration -Wold-style-definition -Wopenmp-simd -Woverflow -Woverlength-strings -Woverloaded-virtual -Woverride-init -Wpacked -Wpacked-bitfield-compat -Wpadded -Wparentheses -Wpedantic -Wpmf-conversions -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wproperty-assign-default -Wprotocol -Wreal-q-constant -Wrealloc-lhs -Wrealloc-lhs-all -Wredundant-decls -Wreorder -Wreturn-local-addr -Wreturn-type -Wselector -Wsequence-point -Wshadow -Wshadow-ivar -Wshift-count-negative -Wshift-count-overflow -Wsign-compare -Wsign-promo -Wsized-deallocation -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-null-sentinel -Wstrict-prototypes -Wstrict-selector-match -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override -Wsurprising -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-enum -Wsync-nand -Wsynth -Wsystem-headers -Wtabs -Wtarget-lifetime -Wtraditional -Wtraditional-conversion -Wtrampolines -Wtrigraphs -Wtype-limits -Wundeclared-selector -Wundef -Wunderflow -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wunsuffixed-float-constants -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-dummy-argument -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wuse-without-only -Wuseless-cast -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvirtual-move-assign -Wvla -Wvolatile-register-var -Wwrite-strings -Wzero-as-null-pointer-constant -Wzerotrip -frequire-return-statement
-Wabi -Wabi-tag -Waddress -Waggregate-return -Waggressive-loop-optimizations -Waliasing -Walign-commons -Wampersand -Warray-bounds -Warray-temporaries -Wassign-intercept -Wattributes -Wbad-function-cast -Wbool-compare -Wbuiltin-macro-redefined -Wc++-compat -Wc++0x-compat -Wc++14-compat -Wc-binding-type -Wc90-c99-compat -Wc99-c11-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wcharacter-truncation -Wchkp -Wclobbered -Wcomment -Wcompare-reals -Wconditionally-supported -Wconversion -Wconversion-extra -Wconversion-null -Wcoverage-mismatch -Wcpp -Wctor-dtor-privacy -Wdate-time -Wdeclaration -after-statement -Wdelete-incomplete -Wdelete-non-virtual-dtor -Wdeprecated -Wdeprecated-declarations -Wdesignated-init -Wdisabled-optimization -Wdiscarded-array-qualifiers -Wdiscarded-qualifiers -Wdiv-by-zero -Wdouble-promotion -Weffc++ -Wempty-body-Wendif-labels -Wenum-compare -Wextra -Wfloat-equal -Wformat-contains-nul -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat-zero-length -Wfree -nonheap-object -Wfunction-elimination -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wimplicit-interface -Wimplicit-procedure -Wincompatible-pointer-types -Winherited-variadic-ctor -Winit-self -Winline -Wint-conversion -Wint-to-pointer-cast -Wintrinsic-shadow -Wintrinsics-std -Winvalid-memory-model -Winvalid-offsetof -Winvalid-pch -Wjump-misses-init -Wline-truncation -Wliteral-suffix -Wlogical -not-括号 -Wlogical-op -Wlong-long -Wmain -Wmaybe-uninitialized -Wmemset-transposed-args -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes-Wmultichar -Wnarrowing -Wnested-externs -Wnoexcept -Wnon-template-friend -Wnon-virtual-dtor -Wnonnull -Wodr -Wold-style-cast -Wold-style-declaration -Wold-style-definition -Wopenmp-simd -Woverflow -Woverlength-strings -Woverloaded-virtual -Woverride-init -Wpacked -Wpacked-bitfield-compat -Wpadded -Wparentheses -Wpedantic -Wpmf-conversions -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wproperty -assign-default -Wprotocol -Wreal-q-constant -Wrealloc-lhs -Wrealloc-lhs-all -Wredundant-decls -Wreorder -Wreturn-local-addr -Wreturn-type -Wselector -Wsequence-point -Wshadow -Wshadow-ivar -Wshift-count-negative -Wshift-count-overflow -Wsign-compare -Wsign-promo -Wsized-deallocation -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-null-sentinel -Wstrict-prototypes -Wstrict-selector-match-Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override -Wsurprising -Wswitch -Wswitch-bool -Wswitch -default -Wswitch-enum -Wsync-nand -Wsynth -Wsystem-headers -Wtabs -Wtarget-lifetime -Wtraditional -Wtraditional-conversion -Wtrampolines -Wtrigraphs -Wtype-limits -Wundeclared-selector -Wundef -Wunderflow -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wunsuffixed-float-constants -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-dummy-argument -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wuse-without-only -Wuseless-cast -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvirtual-move-assign-Wvla -Wvolatile-register-var -Wwrite-strings -Wzero-as-null-pointer-constant -Wzerotrip -frequire-return-statement
This can now be used to call the GCC, i.e.
这现在可以用来调用 GCC,即
gcc $(gcc -Q --help=warning | sed -e 's/^\s*\(\-\S*\)\s*\[\w*\]/ /gp;d' | tr -d '\n')
Note however that this results in warnings due to some warning options only being available for certain languages (e.g. C++
). These could be avoided by using some more regex to only include the options allowed for the current language or by adding an appropriate -Wno-whatever
at the end of the call.
但是请注意,这会导致警告,因为某些警告选项仅适用于某些语言(例如C++
)。这些可以通过使用更多的正则表达式来仅包含当前语言允许的选项或通过-Wno-whatever
在调用结束时添加适当的选项来避免。
回答by Konrad Borowski
It's simply impossible to program with all warnings enabled (unless you are going to ignore them, but then, why bother?). For example, let's assume you use following set of flags: -Wstrict-prototypes -Wtraditional
.
在启用所有警告的情况下进行编程是完全不可能的(除非您打算忽略它们,但是,为什么要打扰?)。例如,假设您使用以下一组标志:-Wstrict-prototypes -Wtraditional
.
Even with two warnings enabled, the following program would complain.
即使启用了两个警告,以下程序也会抱怨。
/tmp $ cat main.c
int main(int argc, char **argv) {
return 0;
}
/tmp $ gcc -Wstrict-prototypes -Wtraditional main.c
main.c: In function ‘main':
main.c:1:5: warning: traditional C rejects ISO C style function definitions [-Wtraditional]
int main(int argc, char **argv) {
^
You may think "well, I'm going to use old style prototypes then". Nope, this won't work.
您可能会想“好吧,我将使用旧式原型”。不,这行不通。
/tmp $ cat main.c
int main(argc, argv)
int argc;
char **argv;
{
return 0;
}
/tmp $ gcc -Wstrict-prototypes -Wtraditional main.c
main.c:1:5: warning: function declaration isn't a prototype [-Wstrict-prototypes]
int main(argc, argv)
^
And no, not specifying any prototype is also wrong, as the compiler will also complain.
不,不指定任何原型也是错误的,因为编译器也会抱怨。
/tmp $ cat main.c
int main() {
return 0;
}
/tmp $ gcc -Wstrict-prototypes -Wtraditional main.c
main.c:1:5: warning: function declaration isn't a prototype [-Wstrict-prototypes]
int main() {
^
If you define any functions inside your program, you cannot use all flags, because the compiler will complain about any imaginable function definition.
如果您在程序中定义任何函数,则不能使用所有标志,因为编译器会抱怨任何可以想象的函数定义。
For C++, this is possible (the -Wtraditional
flag doesn't exist), and very simple programs can be compiled. To enable all warnings, use following list of warnings (probably some warnings are duplicated, because I didn't bother to filter warnings enabled by -Wall
).
对于 C++,这是可能的(该-Wtraditional
标志不存在),并且可以编译非常简单的程序。要启用所有警告,请使用以下警告列表(可能有些警告是重复的,因为我没有费心过滤由 启用的警告-Wall
)。
-Wabi -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Weffc++ -Wstrict-null-sentinel -Wno-non-template-friend -Wold-style-cast -Woverloaded-virtual -Wno-pmf-conversions -Wsign-promo -Wextra -Wall -Waddress -Waggregate-return -Warray-bounds -Wno-attributes -Wno-builtin-macro-redefined -Wc++0x-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wclobbered -Wcomment -Wconversion -Wcoverage-mismatch -Wno-deprecated -Wno-deprecated-declarations -Wdisabled-optimization -Wno-div-by-zero -Wempty-body -Wenum-compare -Wno-endif-labels -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 -Wno-format-contains-nul -Wno-format-extra-args -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wignored-qualifiers -Winit-self -Winline -Wno-int-to-pointer-cast -Wno-invalid-offsetof -Winvalid-pch -Wunsafe-loop-optimizations -Wlogical-op -Wlong-long -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wno-mudflap -Wno-multichar -Wnonnull -Wno-overflow -Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wpadded -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wsign-conversion -Wstack-protector -Wstrict-aliasing=1 -Wstrict-overflow=5 -Wswitch -Wswitch-default -Wswitch-enum -Wsync-nand -Wsystem-headers -Wtrigraphs -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wno-pragmas -Wunreachable-code -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvla -Wvolatile-register-var -Wwrite-strings
回答by Kyle Strand
Someone has created a set of tools for determining the completeset of warnings for a given GCC or Clang version.
有人创建了一组工具来确定给定 GCC 或 Clang 版本的完整警告集。
For GCC, copying from the full list of warnings provided by this tool for your compiler version appears to be the onlyway to ensure that allwarnings are turned on, since (unlike Clang) GCC does not provide -Weverything
.
对于 GCC,从该工具为您的编译器版本提供的完整警告列表中复制似乎是确保所有警告都已打开的唯一方法,因为(与 Clang 不同)GCC 不提供.-Weverything
The tool appears to parse the actual c.opt
file in the GCC source code, so its results shouldbe definitive.
该工具似乎解析c.opt
GCC 源代码中的实际文件,因此其结果应该是确定的。
The repository also contains text files with the warning lists generated for most GCC and Clang versions (currently Clang 3.2 through 3.7 and GCC 3.4 through 5.3).
该存储库还包含带有为大多数 GCC 和 Clang 版本(当前为 Clang 3.2 到 3.7 和 GCC 3.4 到 5.3)生成的警告列表的文本文件。
回答by rockdaboot
Gcc 4.3+ now has -Q --help=warnings, you can even specify --help=warnings,C to just print out the C related warnings.
Gcc 4.3+ 现在有 -Q --help=warnings,你甚至可以指定 --help=warnings,C 来打印出与 C 相关的警告。
I just wrote a m4 module to take advantage of this (also supports clang's -Weverything), see wget_manywarnings.m4
我刚刚写了一个 m4 模块来利用这个(也支持 clang 的 -Weverything),见wget_manywarnings.m4
How to use it is pretty simple, basically the module turns every warn flag on. And you remove warnings as needed - some are really very verbose. Example: configure.ac
如何使用它非常简单,基本上该模块会打开每个警告标志。您可以根据需要删除警告 - 有些确实非常冗长。示例:configure.ac
If you don't use autotools, you'll find the code to turn on all disabled warnings in the m4 module, which basically is the gcc call piped through awk:
如果你不使用 autotools,你会在 m4 模块中找到打开所有禁用警告的代码,这基本上是通过 awk 传输的 gcc 调用:
flags="-Wall -Wextra -Wformat=2 "$(gcc -Wall -Wextra -Wformat=2 -Q --help=warning,C|awk '{ if (($2 == "[disabled]" || $2 == "") && $1!~/=/ && $1~/^-W/&& $1!="-Wall") print $1 }'
flags="-Wall -Wextra -Wformat=2 "$(gcc -Wall -Wextra -Wformat=2 -Q --help=warning,C|awk '{ if (($2 == "[disabled]" || $2 == "") && $1!~/=/ && $1~/^-W/&& $1!="-Wall") print $1 }'
回答by paddy
From this page:
从这个页面:
Note that some warning flags are not implied by
-Wall
. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning. Some of them are enabled by-Wextra
but many of them must be enabled individually.
请注意,某些警告标志并不隐含在
-Wall
. 其中一些警告用户通常不认为有问题的结构,但有时您可能希望检查;其他人警告在某些情况下必要或难以避免的结构,并且没有简单的方法来修改代码以抑制警告。其中一些由 启用,-Wextra
但其中许多必须单独启用。
I guess the question is which ones? Perhaps you could grepthat page for all lines beginning with -W, and get a complete list of warning flags. Then compare those with the lists under -Wall
and -Wextra
. There is also -Wpedantic
, though you are obviously wanting to be even more pedantic still =)
我想问题是哪些?也许您可以为所有以 -W 开头的行grep该页面,并获得完整的警告标志列表。然后比较这些与列表下-Wall
和-Wextra
。还有-Wpedantic
,虽然你显然还想变得更加迂腐=)
回答by Some programmer dude
And I still have no idea if this list is comprehensive.
我仍然不知道这个列表是否全面。
It probably is, but the only list that is 100% comprehensive is the actual source for the compiler. However, GCC is big! And I don't know if all command-line parameters are collected in one place or spread out over several source files. Also note that some warnings are for the pre-processor, some for the actual compiler and some for the linker (which is a completely separate program, and found in the binutils package) so they most likely are spread out.
它可能是,但唯一 100% 全面的列表是编译器的实际来源。然而,海湾合作委员会很大!而且我不知道是所有命令行参数都收集在一个地方还是分布在多个源文件中。还要注意,有些警告是针对预处理器的,有些是针对实际编译器的,有些是针对链接器的(这是一个完全独立的程序,可在 binutils 包中找到),因此它们很可能是分散的。