enh(build): enable same warnings in GCC & clang
Description
It looks like we do not enable exactly the same warnings for clang and for GCC.
For example, using a double
as a bool
ean condition in an if
statement results in a warning emitted only by clang.
It is plausible some are enabled by clang -Wall
but not by gcc -Wall
.
Note:
clang
has -Weverything
which enables, well, everything. But gcc
has not.
Even adding -Wall -Wextra -Wpedantic
does not enable them all. There use to be an issue in their bugtracker, but it is now closed as WONTFIX
.
The only way to enable them all is to extract them with a regex such as:
g++ -Q --help=warning | sed -e 's/^\s*\(\-\S*\)\s*\[\(enabled\|disabled\|available in.* C++.*\)\]/\1 /gp;d' | tr -d '\n'
Which gives (for gcc 11.2.0
) the following beautiful list:
-WNSObject-attribute -Wabi -Wabi-tag -Wabsolute-value -Waddress -Waddress-of-packed-member -Waggregate-return -Waggressive-loop-optimizations -Waligned-new=[none|global|all] -Walloc-zero -Walloca -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 -Wattribute-warning -Wattributes -Wbad-function-cast -Wbool-compare -Wbool-operation -Wbuiltin-declaration-mismatch -Wbuiltin-macro-redefined -Wc++-compat -Wc++11-compat -Wc++14-compat -Wc++17-compat -Wc++20-compat -Wc11-c2x-compat -Wc90-c99-compat -Wc99-c11-compat -Wcannot-profile -Wcast-align -Wcast-align=strict -Wcast-function-type -Wcast-qual -Wcatch-value=<0,3> -Wchar-subscripts -Wclass-conversion -Wclass-memaccess -Wclobbered -Wcomma-subscript -Wcomment -Wconditionally-supported -Wconversion -Wconversion-null -Wcoverage-mismatch -Wcpp -Wctad-maybe-unsupported -Wctor-dtor-privacy -Wdangling-else -Wdate-time -Wdeclaration-after-statement -Wdelete-incomplete -Wdelete-non-virtual-dtor -Wdeprecated -Wdeprecated-copy -Wdeprecated-copy-dtor -Wdeprecated-declarations -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion -Wdesignated-init -Wdisabled-optimization -Wdiscarded-array-qualifiers -Wdiscarded-qualifiers -Wdiv-by-zero -Wdouble-promotion -Wduplicate-decl-specifier -Wduplicated-branches -Wduplicated-cond -Weffc++ -Wempty-body -Wendif-labels -Wenum-compare -Wenum-conversion -Wexceptions -Wexpansion-to-defined -Wextra -Wextra-semi -Wfloat-conversion -Wfloat-equal -Wformat-contains-nul -Wformat-diag -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat-zero-length -Wframe-address -Wfree-nonheap-object -Wif-not-aligned -Wignored-attributes -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winaccessible-base -Wincompatible-pointer-types -Winherited-variadic-ctor -Winit-list-lifetime -Winit-self -Winline -Wint-conversion -Wint-in-bool-context -Wint-to-pointer-cast -Winvalid-imported-macros -Winvalid-memory-model -Winvalid-offsetof -Winvalid-pch -Wjump-misses-init -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-include-dirs -Wmissing-parameter-type -Wmissing-profile -Wmissing-prototypes -Wmultichar -Wmultiple-inheritance -Wmultistatement-macros -Wnamespaces -Wnarrowing -Wnested-externs -Wnoexcept -Wnoexcept-type -Wnon-template-friend -Wnon-virtual-dtor -Wnonnull -Wnonnull-compare -Wnull-dereference -Wodr -Wold-style-cast -Wold-style-declaration -Wold-style-definition -Wopenmp-simd -Woverflow -Woverlength-strings -Woverloaded-virtual -Woverride-init -Woverride-init-side-effects -Wpacked -Wpacked-bitfield-compat -Wpacked-not-aligned -Wpadded -Wparentheses -Wpedantic -Wpessimizing-move -Wplacement-new=<0,2> -Wpmf-conversions -Wpointer-arith -Wpointer-compare -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wprio-ctor-dtor -Wpsabi -Wrange-loop-construct -Wredundant-decls -Wredundant-move -Wredundant-tags -Wregister -Wreorder -Wrestrict -Wreturn-local-addr -Wreturn-type -Wscalar-storage-order -Wsequence-point -Wshadow -Wshadow=compatible-local -Wshadow=local -Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wsign-compare -Wsign-conversion -Wsign-promo -Wsized-deallocation -Wsizeof-array-argument -Wsizeof-array-div -Wsizeof-pointer-div -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-null-sentinel -Wstrict-prototypes -Wstring-compare -Wstringop-overread -Wstringop-truncation -Wsubobject-linkage -Wsuggest-attribute=cold -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-enum -Wswitch-outside-range -Wswitch-unreachable -Wsync-nand -Wsynth -Wsystem-headers -Wtautological-compare -Wtemplates -Wterminate -Wtraditional -Wtraditional-conversion -Wtrampolines -Wtrigraphs -Wtsan -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunsuffixed-float-constants -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -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 -Wzero-length-bounds
Proposal
I don't think it's a good idea to enable them all, because that may require per-target logic (and we may get warnings from STD headers). But if a rapid test proves it won't require complete codebase refactoring, I guess we could go with it.
The simplest approach would probably be to look into that flag list and add ones corresponding to warnings enabled with clang.
I usually compile with the following flags, with enable almost everything (see below for a list of the ones disabled and the reason they are):
-WNSObject-attribute
-Waddress
-Waddress-of-packed-member
-Waggressive-loop-optimizations
-Waligned-new
-Wall
-Walloc-zero
-Walloca
-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
-Wattribute-warning
-Wattributes
-Wbool-compare
-Wbool-operation
-Wbuiltin-declaration-mismatch
-Wbuiltin-macro-redefined
-Wcannot-profile
-Wcast-align
-Wcast-align=strict
-Wcast-function-type
-Wcast-qual
-Wchar-subscripts
-Wclass-conversion
-Wclass-memaccess
-Wclobbered
-Wcomma-subscript
-Wcomment
-Wconversion
-Wconversion-null
-Wcoverage-mismatch
-Wcpp
-Wctad-maybe-unsupported
-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
-Wempty-body
-Wendif-labels
-Wenum-compare
-Wenum-conversion
-Wexceptions
-Wexpansion-to-defined
-Wextra
-Wextra-semi
-Wfloat-conversion
-Wfloat-equal
-Wformat
-Wformat-contains-nul
-Wformat-diag
-Wformat-extra-args
-Wformat-nonliteral
-Wformat-security
-Wformat-signedness
-Wformat-y2k
-Wformat-zero-length
-Wframe-address
-Wfree-nonheap-object
-Whsa
-Wif-not-aligned
-Wignored-attributes
-Wignored-qualifiers
-Winaccessible-base
-Winherited-variadic-ctor
-Winit-list-lifetime
-Winit-self
-Winline
-Wint-in-bool-context
-Wint-to-pointer-cast
-Winvalid-memory-model
-Winvalid-offsetof
-Winvalid-pch
-Wliteral-suffix
-Wlogical-not-parentheses
-Wlogical-op
-Wlto-type-mismatch
-Wmain
-Wmaybe-uninitialized
-Wmemset-elt-size
-Wmemset-transposed-args
-Wmisleading-indentation
-Wmismatched-dealloc
-Wmismatched-new-delete
-Wmismatched-tags
-Wmissing-attributes
-Wmissing-field-initializers
-Wmissing-include-dirs
-Wmissing-profile
-Wmultichar
-Wmultistatement-macros
-Wnarrowing
-Wnoexcept
-Wnoexcept-type
-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
-Wparentheses
-Wpedantic
-Wpessimizing-move
-Wplacement-new=1
-Wpmf-conversions
-Wpointer-arith
-Wpointer-compare
-Wpragmas
-Wprio-ctor-dtor
-Wpsabi
-Wrange-loop-construct
-Wredundant-decls
-Wredundant-move
-Wredundant-tags
-Wregister
-Wreorder
-Wrestrict
-Wreturn-local-addr
-Wreturn-type
-Wscalar-storage-order
-Wsequence-point
-Wshadow
-Wshadow=compatible-local
-Wshadow=local
-Wshift-count-negative
-Wshift-count-overflow
-Wshift-negative-value
-Wsign-compare
-Wsign-conversion
-Wsign-promo
-Wsized-deallocation
-Wsizeof-array-argument
-Wsizeof-array-div
-Wsizeof-pointer-div
-Wsizeof-pointer-memaccess
-Wstack-protector
-Wstrict-null-sentinel
-Wstring-compare
-Wstringop-overread
-Wstringop-truncation
-Wsubobject-linkage
-Wsuggest-attribute=cold
-Wsuggest-attribute=const
-Wsuggest-attribute=format
-Wsuggest-attribute=malloc
-Wsuggest-attribute=noreturn
-Wsuggest-attribute=pure
-Wsuggest-final-methods
-Wsuggest-final-types
-Wsuggest-override
-Wswitch
-Wswitch-bool
-Wswitch-default
-Wswitch-enum
-Wswitch-outside-range
-Wswitch-unreachable
-Wsync-nand
-Wtautological-compare
-Wterminate
-Wtrampolines
-Wtrigraphs
-Wtsan
-Wtype-limits
-Wundef
-Wuninitialized
-Wunknown-pragmas
-Wunreachable-code
-Wunsafe-loop-optimizations
-Wunused
-Wunused-but-set-parameter
-Wunused-but-set-variable
-Wunused-function
-Wunused-label
-Wunused-local-typedefs
-Wunused-macros
-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
-Wzero-length-bound
Or as a one-liner:
-WNSObject-attribute -Waddress -Waddress-of-packed-member -Waggressive-loop-optimizations -Waligned-new -Wall -Walloc-zero -Walloca -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 -Wattribute-warning -Wattributes -Wbool-compare -Wbool-operation -Wbuiltin-declaration-mismatch -Wbuiltin-macro-redefined -Wcannot-profile -Wcast-align -Wcast-align=strict -Wcast-function-type -Wcast-qual -Wchar-subscripts -Wclass-conversion -Wclass-memaccess -Wclobbered -Wcomma-subscript -Wcomment -Wconversion -Wconversion-null -Wcoverage-mismatch -Wcpp -Wctad-maybe-unsupported -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 -Wempty-body -Wendif-labels -Wenum-compare -Wenum-conversion -Wexceptions -Wexpansion-to-defined -Wextra -Wextra-semi -Wfloat-conversion -Wfloat-equal -Wformat -Wformat-contains-nul -Wformat-diag -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat-zero-length -Wframe-address -Wfree-nonheap-object -Whsa -Wif-not-aligned -Wignored-attributes -Wignored-qualifiers -Winaccessible-base -Winherited-variadic-ctor -Winit-list-lifetime -Winit-self -Winline -Wint-in-bool-context -Wint-to-pointer-cast -Winvalid-memory-model -Winvalid-offsetof -Winvalid-pch -Wliteral-suffix -Wlogical-not-parentheses -Wlogical-op -Wlto-type-mismatch -Wmain -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation -Wmismatched-dealloc -Wmismatched-new-delete -Wmismatched-tags -Wmissing-attributes -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-profile -Wmultichar -Wmultistatement-macros -Wnarrowing -Wnoexcept -Wnoexcept-type -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 -Wparentheses -Wpedantic -Wpessimizing-move -Wplacement-new=1 -Wpmf-conversions -Wpointer-arith -Wpointer-compare -Wpragmas -Wprio-ctor-dtor -Wpsabi -Wrange-loop-construct -Wredundant-decls -Wredundant-move -Wredundant-tags -Wregister -Wreorder -Wrestrict -Wreturn-local-addr -Wreturn-type -Wscalar-storage-order -Wsequence-point -Wshadow -Wshadow=compatible-local -Wshadow=local -Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wsign-compare -Wsign-conversion -Wsign-promo -Wsized-deallocation -Wsizeof-array-argument -Wsizeof-array-div -Wsizeof-pointer-div -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-null-sentinel -Wstring-compare -Wstringop-overread -Wstringop-truncation -Wsubobject-linkage -Wsuggest-attribute=cold -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-enum -Wswitch-outside-range -Wswitch-unreachable -Wsync-nand -Wtautological-compare -Wterminate -Wtrampolines -Wtrigraphs -Wtsan -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wunreachable-code -Wunsafe-loop-optimizations -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -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 -Wzero-length-bounds
Note that some are only enabled when some optimizers are.
If you're interested, there are the ones I do not enable and the reason I'm doing so.
Warning | Reason to discard it |
---|---|
-Wabi | Not relevant for my use case. I don't think it's a good idea for Sight either. |
-Wabsolute-value | C and Objective-C only |
-Waggregate-return | Prevents from returning struct s, class es or union s that are aggregates . |
-Wbad-function-cast | C and Objective-C only |
-Wc++-compat | C and Objective-C only |
-Wc11-c2x-compat | C and Objective-C only |
-Wc90-c99-compat | C and Objective-C only |
-Wc99-c11-compat | C and Objective-C only |
-Wdeclaration-after-statement | C and Objective-C only |
-Wdesignated-init | C++20 mandates to support this feature. |
-Wdiscarded-array-qualifiers | C and Objective-C only |
-Wdiscarded-qualifiers | C and Objective-C only |
-Wduplicate-decl-specifier | C and Objective-C only |
-Wimplicit | C and Objective-C only |
-Wimplicit-function-declaration | C and Objective-C only |
-Wimplicit-int | C and Objective-C only |
-Wincompatible-pointer-types | C and Objective-C only |
-Wint-conversion | C and Objective-C only |
-Wjump-misses-init | C and Objective-C only |
-Wlong-long | I don't care about C++98. |
-Wmissing-braces | Disables initalisations of arrays like std::array<int, 3> a = {1, 2, 3}; (requires additional inner braces) |
-Wmissing-declarations | Warns when a function is defined without a prototype (except template s). It's annoying. |
-Wmissing-parameter-type | C and Objective-C only |
-Wmissing-prototypes | C and Objective-C only |
-Wnested-externs | C and Objective-C only |
-Wold-style-declaration | C and Objective-C only |
-Wold-style-definition | C and Objective-C only |
-Woverride-init | C and Objective-C only |
-Woverride-init-side-effects | C and Objective-C only |
-Wpadded | Warns when struct are padded, and I don't care it is. |
-Wpointer-sign | C and Objective-C only |
-Wpointer-to-int-cast | C and Objective-C only |
-Wstrict-prototypes | C and Objective-C only |
-Wsystem-headers | Well, I don't want std namespace warnings in my code. |
-Wtraditional | C and Objective-C only |
-Wunsuffixed-float-constants | C and Objective-C only |
-Wtraditional-conversion | C and Objective-C only |
I also disable these C++-specific warnings:
Warning | Reason to discard it |
---|---|
-Wabi-tag |
I don't care about ABI tags. |
-Wc++11-compat |
Correct is selected by -Wall . |
-Wc++14-compat |
Correct is selected by -Wall . |
-Wc++17-compat |
Correct is selected by -Wall . |
-Wc++20-compat |
Correct is selected by -Wall . |
-Wcatch-value=<0,3> |
All are enabled by -Wall . |
-Wconditionally-supported |
Warn for conditionally-supported (C++11) constructs. We're far in the future. |
-Weffc++ |
It's a style guide. Not a real warning. |
-Winvalid-imported-macros |
Useful, but very heavy. |
-Wmultiple-inheritance |
I sometimes use multiple inheritance. |
-Wnamespaces |
Why would I disable namespace s ? |
-Wsynth |
Warns when g++ synthesis does not match cfront's one. I don't care. |
-Wtemplates |
Forbids template s. Seriously ? |
-Wvirtual-inheritance |
I never use virtual inheritance, but who know... |
In Sight, we may want to add -Wvarargs -Wvariadic-macros
the list of the ignored warnings.
Functional specifications
Same warnings are emitted by both compilers.
Technical specifications
TBA
Test plan
TBA