Open aminya opened 2 years ago
I fully agree that we should do a pass over the existing warning flags set, but I think it should be more nuanced than this.
Right now I know there is some redundant flags. For example, the -Wwrite-strings
is listed as "enabled by default" on Clang's warning page. I know there are others that are currently enabled that we should consider removing while we add new ones that were not previously covered.
Another one to consider is -pedantic-errors
, which according to the GCC documentation does "This is not equivalent to -Werror=pedantic, since there are errors enabled by this option and not enabled by the latter and vice versa." but it gives no further explanation.
Some of these warnings may only be available for C and not C++ in GCC. For example, -Wmissing-prototypes
, -Wnested-externs
, -Wold-style-definition
, and -Wstrict-prototypes
.
more suggestions:
-Wconversion
-Wsign-conversion
-Wmissing-include-dirs
-Wformat=2
-Wunused
-Wunused-variable
-Wcast-align
-Wno-vla
-Wnull-dereference
-Wshadow
and (but only for C++) -Wnon-virtual-dtor -Woverloaded-virtual
'-Wno-vla' seems to disable a warning?
more suggestions:
-Wconversion -Wsign-conversion -Wmissing-include-dirs -Wformat=2 -Wunused -Wunused-variable -Wcast-align -Wno-vla -Wnull-dereference -Wshadow
Many of these are already enabled. Could you find the ones that are not? https://github.com/aminya/project_options/blob/main/src/CompilerWarnings.cmake
'-Wno-vla'
It disallows the use of variable-length C arrays. I am wondering if this is already covered by -Wpedantic
No it's not.
On Wed, 5 Oct 2022, 22:22 Amin Yahyaabadi, @.***> wrote:
'-Wno-vla'
It disallows the use of variable-length C arrays. I am wondering if this is already covered by -Wpedantic
— Reply to this email directly, view it on GitHub https://github.com/aminya/project_options/issues/61#issuecomment-1268930469, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNITBAGULJJFNBSTGMDVUTWBXPO5ANCNFSM5N73VIFQ . You are receiving this because you commented.Message ID: @.***>
Here's my extra warnings:
CLANG_WARNINGS
-Wfloat-equal # warn on comparing floating point with == or !=
-Wglobal-constructors # warn on declare global or static variables with dynamic constructors
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
-Wmissing-noreturn # warn about functions that might be candidates for [[noreturn]]
-Wpacked # warn if a structure is given the packed attribute, but the packed attribute has no effect on the layout or size of the structure
-Wpointer-arith # warn on pointer arithmetic
-Wundef # warn if an undefined identifier is evaluated in an #if directive
GCC_WARNINGS
-Wdisabled-optimization # warn if a requested optimization pass is disabled. often, the problem is that your code is too big or too complex
-Wfloat-equal # warn on comparing floating point with == or !=
-Wglobal-constructors # warn on declare global or static variables with dynamic constructors
-Winvalid-pch # warn if a precompiled header is found in the search path but cannot be used
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
-Wmissing-format-attribute # Warn about function pointers that might be candidates for format attributes
-Wmissing-include-dirs # warn if a user-supplied include directory does not exist
-Wmissing-noreturn # warn about functions that might be candidates for [[noreturn]]
-Wpacked # warn if a structure is given the packed attribute, but the packed attribute has no effect on the layout or size of the structure
-Wpointer-arith # warn on pointer arithmetic
-Wredundant-decls # warn if anything is declared more than once in the same scope, even in cases where multiple declaration is valid and changes nothing
-Wundef # warn if an undefined identifier is evaluated in an #if directive
Note that -Wglobal-constructors
warns on global singleton so it will be annoying when using unit test library such as google test.
There is a repo on github with an up to date list of all warnings for gcc and clang, including only unique ones, it can be used to extract interesting warnings, diffs between versions are also available:
https://github.com/pkolbus/compiler-warnings/blob/main/gcc/warnings-unique-13.txt https://github.com/pkolbus/compiler-warnings/blob/main/clang/warnings-unique-16.txt
There are other Clang warnings that we have not added. We have already enabled the most pedantic ones, so I think adding these will complete the list and would be beneficial.
https://clang.llvm.org/docs/DiagnosticsReference.html
Upvote & Fund
I am using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog.