[英]How can I turn on (literally) ALL of GCC's warnings?
I would like to enable—literally— all of the warnings that GCC has.我想启用 GCC 的所有警告。 (You'd think it would be easy...) (你会认为这很容易......)
You'd think -Wall might do the trick, but nope!你会认为-Wall可能会成功,但不! You still need -Wextra .你仍然需要-Wextra 。
You'd think -Wextra
might do the trick, but nope!你会认为-Wextra
可能会成功,但不! Not all of the warnings listed here (for example, -Wshadow ) are enabled by this.并非此处列出的所有警告(例如-Wshadow )都由此启用。 And I still don't have any idea if this list is comprehensive.我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has?我如何告诉 GCC 启用(没有 if's, and's, or but's!)它的所有警告?
I would like to enable -- literally -- ALL of the warnings that GCC has.我想启用 - 字面意思 - GCC 的所有警告。 (You'd think it would be easy...) (你会认为这很容易......)
You'd think -Wall
might do the trick, but nope!你会认为-Wall
可能会成功,但不是! Still need -Wextra
.仍然需要-Wextra
。
You'd think -Wextra
might do the trick, but nope!你会认为-Wextra
可能会成功,但不是! Not all of the warnings listed here (for example, -Wshadow
) are enabled by this.并非此处列出的所有警告(例如, -Wshadow
)都由此启用。 And I still have no idea if this list is comprehensive.我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has?我如何告诉 GCC 启用(没有 if、and 或 but !)它有的所有警告?
I would like to enable -- literally -- ALL of the warnings that GCC has.我想启用 - 字面意思 - GCC 的所有警告。 (You'd think it would be easy...) (你会认为这很容易......)
You'd think -Wall
might do the trick, but nope!你会认为-Wall
可能会成功,但不是! Still need -Wextra
.仍然需要-Wextra
。
You'd think -Wextra
might do the trick, but nope!你会认为-Wextra
可能会成功,但不是! Not all of the warnings listed here (for example, -Wshadow
) are enabled by this.并非此处列出的所有警告(例如, -Wshadow
)都由此启用。 And I still have no idea if this list is comprehensive.我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has?我如何告诉 GCC 启用(没有 if、and 或 but !)它有的所有警告?
I would like to enable -- literally -- ALL of the warnings that GCC has.我想启用 - 字面意思 - GCC 的所有警告。 (You'd think it would be easy...) (你会认为这很容易......)
You'd think -Wall
might do the trick, but nope!你会认为-Wall
可能会成功,但不是! Still need -Wextra
.仍然需要-Wextra
。
You'd think -Wextra
might do the trick, but nope!你会认为-Wextra
可能会成功,但不是! Not all of the warnings listed here (for example, -Wshadow
) are enabled by this.并非此处列出的所有警告(例如, -Wshadow
)都由此启用。 And I still have no idea if this list is comprehensive.我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has?我如何告诉 GCC 启用(没有 if、and 或 but !)它有的所有警告?
I would like to enable -- literally -- ALL of the warnings that GCC has.我想启用 - 字面意思 - GCC 的所有警告。 (You'd think it would be easy...) (你会认为这很容易......)
You'd think -Wall
might do the trick, but nope!你会认为-Wall
可能会成功,但不是! Still need -Wextra
.仍然需要-Wextra
。
You'd think -Wextra
might do the trick, but nope!你会认为-Wextra
可能会成功,但不是! Not all of the warnings listed here (for example, -Wshadow
) are enabled by this.并非此处列出的所有警告(例如, -Wshadow
)都由此启用。 And I still have no idea if this list is comprehensive.我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has?我如何告诉 GCC 启用(没有 if、and 或 but !)它有的所有警告?
I would like to enable -- literally -- ALL of the warnings that GCC has.我想启用 - 字面意思 - GCC 的所有警告。 (You'd think it would be easy...) (你会认为这很容易......)
You'd think -Wall
might do the trick, but nope!你会认为-Wall
可能会成功,但不是! Still need -Wextra
.仍然需要-Wextra
。
You'd think -Wextra
might do the trick, but nope!你会认为-Wextra
可能会成功,但不是! Not all of the warnings listed here (for example, -Wshadow
) are enabled by this.并非此处列出的所有警告(例如, -Wshadow
)都由此启用。 And I still have no idea if this list is comprehensive.我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has?我如何告诉 GCC 启用(没有 if、and 或 but !)它有的所有警告?
I would like to enable -- literally -- ALL of the warnings that GCC has.我想启用 - 字面意思 - GCC 的所有警告。 (You'd think it would be easy...) (你会认为这很容易......)
You'd think -Wall
might do the trick, but nope!你会认为-Wall
可能会成功,但不是! Still need -Wextra
.仍然需要-Wextra
。
You'd think -Wextra
might do the trick, but nope!你会认为-Wextra
可能会成功,但不是! Not all of the warnings listed here (for example, -Wshadow
) are enabled by this.并非此处列出的所有警告(例如, -Wshadow
)都由此启用。 And I still have no idea if this list is comprehensive.我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has?我如何告诉 GCC 启用(没有 if、and 或 but !)它有的所有警告?
I would like to enable -- literally -- ALL of the warnings that GCC has.我想启用 - 字面意思 - GCC 的所有警告。 (You'd think it would be easy...) (你会认为这很容易......)
You'd think -Wall
might do the trick, but nope!你会认为-Wall
可能会成功,但不是! Still need -Wextra
.仍然需要-Wextra
。
You'd think -Wextra
might do the trick, but nope!你会认为-Wextra
可能会成功,但不是! Not all of the warnings listed here (for example, -Wshadow
) are enabled by this.并非此处列出的所有警告(例如, -Wshadow
)都由此启用。 And I still have no idea if this list is comprehensive.我仍然不知道这个列表是否全面。
How do I tell GCC to enable (no if's, and's, or but's!) all the warnings it has?我如何告诉 GCC 启用(没有 if、and 或 but !)它有的所有警告?
I gathered information from the other postings and one-by-one tested the warnings in the test for a C++ library.我从其他帖子中收集了信息,并对 C++ 库的测试中的警告进行了逐一测试。
Using the list from Haatschii and his/her method of getting the full list for GCC 11:使用Haatschii的列表和他/她获取 GCC 11 完整列表的方法:
gcc -Wall -Wextra -Wpedantic -Q --help=warning
Of all these warnings some do not apply to C++, so here it is a list of warnings and some minimal comments that work for the tests of my C++ project.在所有这些警告中,有些不适用于 C++,因此这里列出了适用于我的 C++ 项目测试的警告和一些最小注释。
Take into account, that:考虑到:
The list is basically in alphabetical order, with some minimal bunching to save vertical space.该列表基本上是按字母顺序排列的,为了节省垂直空间而进行了一些最小化。 As a bonus, it is formatted for use in a CMake project.作为奖励,它被格式化用于CMake项目。
Now the list:现在列表:
target_compile_options(
target
PRIVATE
$<CXX_COMPILER_ID:GNU>:
-Werror
-Wall
-Wextra # (activates -Wunknown-pragmas)
-Wextra-semi
-Wpedantic
# -Wabi=13 -Wabi-tag (maybe important when linking with very old libraries)
-Waddress -Waddress-of-packed-member
# -Waggregate-return (disallow return classes or structs, seems a C-compatibility warning)
-Waggressive-loop-optimizations
-Walloc-zero # -Walloc-size-larger-than=
-Walloca # -Walloca-larger-than=
-Wanalyzer-double-fclose -Wanalyzer-double-free -Wanalyzer-exposure-through-output-file -Wanalyzer-file-leak -Wanalyzer-free-of-non-heap -Wanalyzer-malloc-leak -Wanalyzer-mismatching-deallocation -Wanalyzer-null-argument -Wanalyzer-null-dereference -Wanalyzer-possible-null-argument -Wanalyzer-possible-null-dereference -Wanalyzer-shift-count-negative -Wanalyzer-shift-count-overflow -Wanalyzer-stale-setjmp-buffer -Wanalyzer-tainted-array-index -Wanalyzer-too-complex -Wanalyzer-unsafe-call-within-signal-handler -Wanalyzer-use-after-free -Wanalyzer-use-of-pointer-in-stale-stack-frame -Wanalyzer-write-to-const -Wanalyzer-write-to-string-literal
-Warith-conversion
-Warray-bounds -Warray-parameter # -Warray-bounds=<0,2> -Warray-parameter=<0,2>
-Wattribute-warning -Wattributes
-Wbool-compare -Wbool-operation
-Wbuiltin-declaration-mismatch -Wbuiltin-macro-redefined
-Wc++0x-compat -Wc++14-compat -Wc++17-compat -Wc++1z-compat -Wc++20-compat -Wc++2a-compat
-Wcannot-profile
-Wcast-align -Wcast-align=strict -Wcast-function-type -Wcast-qual
-Wcatch-value # -Wcatch-value=<0, 3>
-Wchar-subscripts -Wclobbered -Wcomment # (same as -Wcomments)
-Wconditionally-supported
-Wconversion -Wconversion-null
-Wcoverage-mismatch -Wcpp
# -Wctad-maybe-unsupported (make ctad explicitly necessary)
-Wctor-dtor-privacy
-Wdangling-else -Wdate-time
-Wdelete-incomplete -Wdelete-non-virtual-dtor
-Wdeprecated -Wdeprecated-copy -Wdeprecated-copy-dtor -Wdeprecated-declarations -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion
-Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion
-Wduplicated-branches -Wduplicated-cond
# -Weffc++ (doesn't allow some advanced techniques, such as CRTP)
-Wempty-body -Wendif-labels
-Wenum-compare -Wenum-conversion
-Wexpansion-to-defined
-Wexceptions
# -Wextra (see above)
-Wfloat-conversion # -Wfloat-equal (disallows float equality)
-Wformat-truncation -Wformat=2 -Wformat-diag -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-truncation -Wformat-y2k -Wformat-zero-length # -Wformat-overflow=<0,2>
-Wframe-address # -Wframe-larger-than=<byte-size>
-Wfree-nonheap-object -Whsa -Wif-not-aligned
-Wignored-attributes -Wignored-qualifiers
-Wimplicit-fallthrough#=3 # -Wimplicit-fallthrough=<0,5>
-Winit-self
# -Winline
-Wint-in-bool-context -Wint-to-pointer-cast
-Winvalid-imported-macros
-Winvalid-memory-model -Winvalid-offsetof -Winvalid-pch
-Wignored-qualifiers
# -Wlarger-than=<byte-size> # (disallow large objects types? in executable)
-Wliteral-suffix
-Wlogical-not-parentheses -Wlogical-op
-Wlong-long -Wlto-type-mismatch -Wmain -Wmaybe-uninitialized
-Wmemset-elt-size -Wmemset-transposed-args
-Wmisleading-indentation
-Wmismatched-dealloc -Wmismatched-new-delete -Wmismatched-tags
-Wmissing-attributes -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wmissing-profile
-Wmultichar
# -Wmultiple-inheritance (disallows composition by inheritance)
-Wmultistatement-macros
# -Wnamespaces (disallows use of namespaces, seems a C-tool)
-Wnarrowing
-Wnoexcept -Wnoexcept-type
-Wnormalized #=nfc -Wnormalized=[none|id|nfc|nfkc]
-Wnon-template-friend
-Wnon-virtual-dtor
-Wnonnull -Wnonnull-compare -Wnull-dereference
-Wodr -Wold-style-cast -Wopenmp-simd -Woverflow
-Woverlength-strings -Woverloaded-virtual
-Wpacked -Wpacked-bitfield-compat -Wpacked-not-aligned
# -Wpadded (disallows structs that need padding for alignment)
-Wparentheses
# -Wpedantic (see above)
-Wpessimizing-move -Wplacement-new #=1 -Wplacement-new=<0,2>
-Wpmf-conversions
-Wpointer-arith -Wpointer-compare
-Wpragmas -Wprio-ctor-dtor -Wpsabi
-Wrange-loop-construct -Wredundant-decls -Wredundant-move -Wredundant-tags -Wregister
-Wreturn-local-addr -Wreturn-type
-Wrestrict -Wreorder
-Wscalar-storage-order -Wsequence-point
-Wshadow -Wshadow-compatible-local -Wshadow-local -Wshadow=compatible-local -Wshadow=local
-Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wshift-overflow #=1 -Wshift-overflow=<0,2>
-Wsign-compare -Wsign-conversion -Wsign-promo
-Wsized-deallocation
-Wsizeof-array-argument -Wsizeof-array-div -Wsizeof-pointer-div -Wsizeof-pointer-memaccess
-Wstack-protector # -Wstack-usage=<byte-size>
-Wstrict-aliasing #=3 -Wstrict-aliasing=<0,3>
-Wstrict-null-sentinel #=1 -Wstrict-overflow=<0,5>
-Wstrict-overflow #=1 -Wstrict-overflow=<0,5>
-Wstring-compare
-Wstringop-overflow #=2 -Wstringop-overflow=<0,4>
-Wstringop-overread -Wstringop-truncation
-Wsubobject-linkage
-Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types
-Wswitch -Wswitch-bool -Wswitch-default -Wswitch-enum -Wswitch-outside-range -Wswitch-unreachable
-Wsync-nand -Wsynth
# -Wsystem-headers (expects system headers to be warning-compliant which they are not)
-Wtautological-compare
# -Wtemplates (disallows templates, C-tool)
-Wtrampolines -Wtrigraphs -Wtsan
-Wtype-limits -Wundef -Wuninitialized
-Wno-unknown-pragmas # (see above) -Wunknown-pragmas (other compilers need their own pragmas for their warnings)
-Wunreachable-code -Wunsafe-loop-optimizations
-Wunused -Wunused-parameter -Wunused-but-set-variable
# -Wunused-const-variable #=2
-Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable
-Wuseless-cast
-Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvexing-parse -Wvirtual-inheritance -Wvirtual-move-assign
-Wvla -Wvla-parameter
-Wvolatile -Wvolatile-register-var
-Wwrite-strings
-Wzero-as-null-pointer-constant
>
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.