Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more compiler warnings by default #61

Open
aminya opened this issue Feb 10, 2022 · 10 comments
Open

Adding more compiler warnings by default #61

aminya opened this issue Feb 10, 2022 · 10 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@aminya
Copy link
Owner

aminya commented Feb 10, 2022

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

  • 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.

Fund with Polar
@aminya aminya added the enhancement New feature or request label Feb 10, 2022
@aminya aminya pinned this issue Feb 10, 2022
@aminya aminya added the good first issue Good for newcomers label Feb 10, 2022
@lefticus
Copy link
Contributor

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
Copy link

ljishen commented Feb 15, 2022

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
Copy link

janwilmans commented Oct 5, 2022

more suggestions:

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

@janwilmans
Copy link

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

@ClausKlein
Copy link
Contributor

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

@aminya
Copy link
Owner Author

aminya commented Oct 5, 2022

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
Copy link
Owner Author

aminya commented Oct 5, 2022

'-Wno-vla'

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

@janwilmans
Copy link

janwilmans commented Oct 11, 2022 via email

@aminya aminya added this to the v1.0.0 milestone Oct 30, 2022
@FeignClaims
Copy link
Contributor

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
Copy link
Contributor

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

@aminya aminya unpinned this issue Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

7 participants