aminya / project_options

A general-purpose CMake library that provides functions that improve the CMake experience following the best practices.
https://aminya.github.io/project_options/
MIT License
351 stars 52 forks source link

Adding more compiler warnings by default #61

Open aminya opened 2 years ago

aminya commented 2 years ago

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.

-Wformat-overflow
-Wformat-nonliteral
-Wformat-truncation=2
-fno-common
-Wcast-qual
-Wdeprecated
-Wmissing-declarations
-Wmissing-prototypes
-Wnested-externs
-Wold-style-definition
-Wpointer-arith
-Wsign-compare
-Wstrict-prototypes
-Wundef
-Wwrite-strings

https://clang.llvm.org/docs/DiagnosticsReference.html

Upvote & Fund

Fund with Polar

lefticus commented 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.

ljishen commented 2 years ago

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.

janwilmans commented 2 years ago

more suggestions:

-Wconversion 
-Wsign-conversion 
-Wmissing-include-dirs 
-Wformat=2 
-Wunused 
-Wunused-variable 
-Wcast-align 
-Wno-vla 
-Wnull-dereference
-Wshadow
janwilmans commented 2 years ago

and (but only for C++) -Wnon-virtual-dtor -Woverloaded-virtual

ClausKlein commented 2 years ago

'-Wno-vla' seems to disable a warning?

aminya commented 2 years ago

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

aminya commented 2 years ago

'-Wno-vla'

It disallows the use of variable-length C arrays. I am wondering if this is already covered by -Wpedantic

janwilmans commented 2 years ago

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: @.***>

FeignClaims commented 1 year ago

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.

Project579 commented 1 year ago

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