How can I turn on (literally) ALL of GCC's warnings?
Asked Answered
N

8

259

I would like to enable—literally—all of the warnings that GCC has. (You'd think it would be easy...)

  • You'd think -Wall might do the trick, but nope! You still need -Wextra.

  • You'd think -Wextra might do the trick, but nope! Not all of the warnings listed here (for example, -Wshadow) are enabled by this. 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?

Natascha answered 30/7, 2012 at 2:39 Comment(15)
Including mutually incompatible warnings? Why?Presentday
@Arafangion: Like which ones? I haven't heard of those before.Natascha
Well, for example, I usually tell GCC to be pedantic and confirm to C99, or C89 depending on the project. Obviously, using C99 constructs is going to cause more warnings in C89 (if it compiles at all). Are you suggesting that you want to enable all warnings, for all the C standards that GCC supports? And what about those other "warning" flags that actually disable warnings? Please clarify the question and state WHY you want them enabled, this is a pointless excercise otherwise.Presentday
@Arafangion: I don't understand what's "unclear" about the question -- yes, I'd like to turn on all warnings that are applicable to my code, no matter how pedantic. As for the reason, it's very simple: I have found some of the warnings that are not turned on by -Wall or -Wextra to be helpful, and so I want to try out the rest to see if I can improve my code. It's as simple as that.Natascha
Why not just add all the warnings that the document doesn't say is turned on be e.g. -Wall and -Wextra? Personally I use -Wall -Wextra -Weffc++ -Wconversion -Wsign-conversion -Woverloaded-virtual, it covers most cases.Emulous
By the way, what is it you want the compiler to warn about? It's easier to answer that specific question. Also, for a complete list of warning options, there is only one definitive source: The actual source code for the compiler!Emulous
@JoachimPileborg: "What is it you want the compiler to warn about?" Potential errors and/or bad style? I mean, if I knew all the exact warnings then I would've just turned them on manually, no need to pose the question. If the answer is indeed "you have to look at the source code to find all of them" then please post it as the answer!Natascha
clang 3.1 offers -Weverything.Grouchy
Almost a duplicate (and many useful answers): #5088960Veii
@JoachimPileborg: Turning on -Weffc++ is probably not going to be helpful with a ANSI C codebase. C++ is a different language.Presentday
@Presentday Well, the question is tagged C++ so... :)Emulous
@JoachimPileborg: Ah, it is now! Well, people should point out that g++ is to be used, too many people regard "GCC" as the C compiler, rather than "Gnu Compiler Collection".Presentday
@JoachimPileborg And now there is (finally) an automated way to extract the warnings from the source: github.com/barro/compiler-warningsNigercongo
After -Wall and -Wextra (and perhaps -Wpedantic) is arguable what other warnings to activate. The best advise I can think of is to compile (and make sure the code works) with -O3. That is, optimization exposes bugs.Houle
You are going to be buried under warning if you somehow managed to enable all warningsFunereal
M
161

You can't.

The manual for GCC 4.4.0 is only comprehensive for that version, but it does list all the possible warnings for 4.4.0. They're not all on the page you link to though. For instance, some language-specific options are on the pages for C++ options or Objective-C options. To find them all, you're better off looking at the Options Summary

Turning on everything would include -Wdouble-promotion which is only relevant on CPUs with a 32-bit single-precision floating-point unit which implements float in hardware, but emulates double in software. Doing calculations as double would use the software emulation and be slower. That's relevant for some embedded CPUs, but completely irrelevant for modern desktop CPUs with hardware support for 64-bit floating-point.

Another warning that's not usually useful is -Wtraditional, which warns about perfectly well formed code that has a different meaning (or doesn't work) in traditional C, e.g., "string " "concatenation", or ISO C function definitions! Do you really care about compatibility with 30 year old compilers? Do you really want a warning for writing int inc(int i) { return i+1; }?

I think -Weffc++ is too noisy to be useful. It's based on the outdated first edition of Effective C++ and warns about constructs which are perfectly valid C++ (and for which the guidelines changed in later editions of the book). I don't want to be warned that I haven't initialized a std::string member in my constructor; it has a default constructor that does exactly what I want. Why should I write m_str() to call it? The -Weffc++ warnings that would be helpful are too difficult for the compiler to detect accurately (giving false negatives), and the ones that aren't useful, such as initializing all members explicitly, just produce too much noise, giving false positives.

Luc Danton provided a great example of useless warnings from -Waggregate-return that almost certainly never makes sense for C++ code.

I.e., you don't really want all warnings; you just think you do.

Go through the manual, read about them, decide which you might want to enable, and try them. Reading your compiler's manual is a Good ThingTM anyway, taking a shortcut and enabling warnings you don't understand is not a very good idea, especially if it's to avoid having to RTFM.

Anyone who just turns on everything is probably either doing so because they're clueless because or a pointy-haired boss said "no warnings."

Some warnings are important, and some aren't. You have to be discriminating or you mess up your program. Consider, for instance, -Wdouble-promotion. If you're working on an embedded system you might want this; if you're working on a desktop system you probably don't. And do you want -Wtraditional? I doubt it.

See also -Wall-all to enable all warnings which is closed as WONTFIX.

In response to DevSolar's complaint about makefiles needing to use different warnings depending on compiler version, if -Wall -Wextra isn't suitable then it's not difficult to use compiler-specific and version-specific CFLAGS:

compiler_name := $(notdir $(CC))
ifeq ($(compiler_name),gcc)
compiler_version := $(basename $(shell $(CC) -dumpversion))
endif
ifeq ($(compile_name),clang)
compiler_version := $(shell $(CC) --version | awk 'NR==1{print $$3}')
endif
# ...
wflags.gcc.base := -Wall -Wextra
wflags.gcc.4.7 := -Wzero-as-null-pointer-constant
wflags.gcc.4.8 := $(wflags.gcc.4.7)
wflags.clang.base := -Wall -Wextra
wflags.clang.3.2 := -Weverything
CFLAGS += $(wflags.$(compiler_name).base) $(wflags.$(compiler_name).$(compiler_version))
Mainsail answered 30/7, 2012 at 11:9 Comment(17)
"Go through the manual, read about them, decide which you might want to enable, try them." The problem here are the steps you left out: "Re-visit the manual for each and every compiler version and adapt your list of warnings because they are a-changing. Make your Makefiles check the exact compiler version and use a different list of warnings for each of them." We have maintainer-maintained levels of optimizations; why couldn't they be bothered with providing the same service for warnings?Cryptocrystalline
@DevSolar, new warnings are documented in the release notes for each version (e.g. 4.5, 4.6) so you only need to read them when upgrading your compiler to find out about new warnings, and surely you can be bothered to read the documentation for your compilers, not doing so is simply unprofessional and lazy.Mainsail
There has been discussion of something like -W1, -W2 (e.g. see the long thread starting at gcc.gnu.org/ml/gcc/2012-04/msg00087.html) but they "couldn't be bothered" because noone has proposed a design or done the work yet, and there aren't infinite developer resources to work on every user's pet list of demands. It's open source, why don't you do it? Patches welcome.Mainsail
@JonathanWakely: I have my projects, and GCC isn't among them. I point to a weakness in their product. Either they fix it or they accept the blame for not doing so, but it's not up to me to fix it for them, OSS be damned.Cryptocrystalline
@DevSolar, AFAIK no user ever requested -Wn, it was (semi-)proposed by GCC devs in discussion on the GCC list. How are the devs to know people want it if noone's ever requested it? Are we meant to be psychic? Scour every post on the internet to find what people consider to be weaknesses? If you want something, ask for it, don't bitch about it.Mainsail
Besides which, the maintainers already do maintain levels of warnings, they decide what should be in -Wall and what should be in -Wextra, all that's missing is -Wover9000 for "everything else". Most new warnings get included in -Wall, or are more refined controls over existing warnings (e.g. instead of -Wunused you can use -Wunused-but-set-variable -Wunused-but-set-parameter to only get some of the -Wunused warnings.) What exactly are you complaining that they don't bother to do?Mainsail
@JonathanWakely: "If you want something, ask for it, don't bitch about it." -- I am not obliged to participate in the GCC project in order to critizise it, especially not if #31573 has been flagged as WONTFIX already. That puts this subject from the "ask about it" into the "bitch about it" ballpark.Cryptocrystalline
@DevSolar, my answer already explains why -Wall-all is not a good idea. As I said two comments up, what else is missing? Criticism is fine, but don't assume it's because noone could be bothered to do something, especially when you can't be bothered to open an enhancement request instead of complaining.Mainsail
@JonathanWakely: Your answer explains why you and other GCC maintainers think that -Wall-all is not a good idea. The question, feature requests you yourself linked, and my comments explain why others do think it would be a good idea. My comment also explained why I don't bother to open an enhancement request that would be a duplicate to one already closed as WONTFIX. That's just as it is.Cryptocrystalline
-Weverything is the better solution, I think, than the gcc strategy of not giving such an option. I use that flag with clang because my philosophy is that I want all warnings on by default (because someone thought it was helpful enough to add to the compiler), and if I don't like it, I turn off that warning specifically. The point is that you don't know about warnings that don't trigger, but you do know about warnings you don't want that do trigger, and they are easily turned off.Arguable
In defense of avoiding reading the manual: I am honestly not convinced that there aren't many, many more useful things to read, such as Effective C++ or several useful SO posts, and I have limited time and memory. At some point, if your tools require you to imbibe a fire-hydrant of information in order to use them properly, then they're no longer helping you.Nigercongo
@KyleStrand, sure, in which case just use -Wall or -Wall -Wextra and rely on the maintainers to have enabled all the generally useful warnings with those options, which is the whole point of those options. If it's not included in one of those then you probably don't need it. If you think you're missing out on something useful then read the manual. And you don't need to read the entire manual to know about possibly interesting warnings anyway, only gcc.gnu.org/onlinedocs/gcc/Option-Summary.htmlMainsail
@JonathanWakely Yeah, but they're paltry. The easiest way to see what warnings might be relevant to your code is to see which warnings are triggered by your code; at that point you can see a relevant, real-life example of the potentially-dangerous code before deciding whether or not to disable the warning. This can be easily done with Clang's -Weverything option, but is impossible to do with GCC.Nigercongo
FYI, there's finally a way to figure out the complete list of warnings for a given version of GCC: github.com/barro/compiler-warningsNigercongo
'Anyone who just turns on everything is probably either doing so because they're clueless because or a pointy-haired boss said "no warnings."' - You might be clueless what you DON'T know, and scanning through warnings (and selectively grep/grep -v) you can find a relevant warning that had never occurred to you, because you are not a GCC/Clang developer yourself... I found C++ code problems even in Stroustrup's own C++ files! E.g. do a -Weverything on his std_lib_facilities.h as the easiest demonstration.Spectrometer
@JonathanWakely Actually, sir, I can't reproduce the ambiguity using example code from cppreference.com without -pedantic. I read it in this SO answer. And I'm just a C++ Beginner reading C++ Primer 5th ed. How could I even know I need to read though the whole document of warning options to experiment the ambiguity out? I think I should try out clang for a period of time now.Die
gcc 11 deemed that "-Wtraditional is valid for C/ObjC but not for C++".Houle
B
96

I would agree with the previous answers that it is probably not beneficial to enable literally all warnings, however GCC does provide a reasonably convenient way to achieve this. The command

gcc -Q --help=warning

provides a list of all supported warning options with information on whether they are active. This can by the way be used to find out which options are (not) enabled by e.g. -Wall and -Wextra

gcc -Wall -Wextra -Q --help=warning

To enable all the warnings you can use some regex to extract the command line parameters

gcc -Q --help=warning | sed -e 's/^\s*\(\-\S*\)\s*\[\w*\]/\1 /gp;d' | tr -d '\n'

For my current GCC this gives:

-Wabi -Wabi-tag -Waddress -Waggregate-return -Waggressive-loop-optimizations -Waliasing -Walign-commons -Wampersand -Warray-bounds -Warray-temporaries -Wassign-intercept -Wattributes -Wbad-function-cast -Wbool-compare -Wbuiltin-macro-redefined -Wc++-compat -Wc++0x-compat -Wc++14-compat -Wc-binding-type -Wc90-c99-compat -Wc99-c11-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wcharacter-truncation -Wchkp -Wclobbered -Wcomment -Wcompare-reals -Wconditionally-supported -Wconversion -Wconversion-extra -Wconversion-null -Wcoverage-mismatch -Wcpp -Wctor-dtor-privacy -Wdate-time -Wdeclaration-after-statement -Wdelete-incomplete -Wdelete-non-virtual-dtor -Wdeprecated -Wdeprecated-declarations -Wdesignated-init -Wdisabled-optimization -Wdiscarded-array-qualifiers -Wdiscarded-qualifiers -Wdiv-by-zero -Wdouble-promotion -Weffc++ -Wempty-body -Wendif-labels -Wenum-compare -Wextra -Wfloat-equal -Wformat-contains-nul -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat-zero-length -Wfree-nonheap-object -Wfunction-elimination -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wimplicit-interface -Wimplicit-procedure -Wincompatible-pointer-types -Winherited-variadic-ctor -Winit-self -Winline -Wint-conversion -Wint-to-pointer-cast -Wintrinsic-shadow -Wintrinsics-std -Winvalid-memory-model -Winvalid-offsetof -Winvalid-pch -Wjump-misses-init -Wline-truncation -Wliteral-suffix -Wlogical-not-parentheses -Wlogical-op -Wlong-long -Wmain -Wmaybe-uninitialized -Wmemset-transposed-args -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes -Wmultichar -Wnarrowing -Wnested-externs -Wnoexcept -Wnon-template-friend -Wnon-virtual-dtor -Wnonnull -Wodr -Wold-style-cast -Wold-style-declaration -Wold-style-definition -Wopenmp-simd -Woverflow -Woverlength-strings -Woverloaded-virtual -Woverride-init -Wpacked -Wpacked-bitfield-compat -Wpadded -Wparentheses -Wpedantic -Wpmf-conversions -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wproperty-assign-default -Wprotocol -Wreal-q-constant -Wrealloc-lhs -Wrealloc-lhs-all -Wredundant-decls -Wreorder -Wreturn-local-addr -Wreturn-type -Wselector -Wsequence-point -Wshadow -Wshadow-ivar -Wshift-count-negative -Wshift-count-overflow -Wsign-compare -Wsign-promo -Wsized-deallocation -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-null-sentinel -Wstrict-prototypes -Wstrict-selector-match -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override -Wsurprising -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-enum -Wsync-nand -Wsynth -Wsystem-headers -Wtabs -Wtarget-lifetime -Wtraditional -Wtraditional-conversion -Wtrampolines -Wtrigraphs -Wtype-limits -Wundeclared-selector -Wundef -Wunderflow -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wunsuffixed-float-constants -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-dummy-argument -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wuse-without-only -Wuseless-cast -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvirtual-move-assign -Wvla -Wvolatile-register-var -Wwrite-strings -Wzero-as-null-pointer-constant -Wzerotrip -frequire-return-statement

This can now be used to call the GCC, i.e.

gcc $(gcc -Q --help=warning | sed -e 's/^\s*\(\-\S*\)\s*\[\w*\]/\1 /gp;d' | tr -d '\n')

Note however that this results in warnings due to some warning options only being available for certain languages (e.g., C++). These could be avoided by using some more regex to only include the options allowed for the current language or by adding an appropriate -Wno-whatever at the end of the call.

Blayze answered 24/1, 2016 at 2:0 Comment(6)
I'm afraid it is not practical. Gcc has shown me warnings from std lib.Benitabenites
@ValentinHeinitz As I said I don't think it is beneficial to enable literally all warnings, but this is was what OP asked for. However I think by explicitly removing some problematic warnings already mentioned in other answers (e.g. by adding respective -Wno-whatever at the end of the call), this can be of practical use.Blayze
@ValentinHeinitz You can prevent gcc from issuing warnings for system/std/3rd-party headers by using -isystem instead of -I for the relevant directories.Nigercongo
This should be the accepted answer as this actually and directly answers the question.Spectrometer
Can someone clarify: you can enable every GCC warnings but also add additional flags to disable individual flags/checks?Epigene
@Epigene Yes, that is correct. Note that the order of the arguments is relevant. E.g. gcc -Wabi -Wno-abi -Q --help=warning will show -Wabi as disabled, while gcc -Wno-abi -Wabi -Q --help=warning will show -Wabi as enabled.Blayze
H
18

It's simply impossible to program with all warnings enabled (unless you are going to ignore them, but then, why bother?). For example, let's assume you use following set of flags: -Wstrict-prototypes -Wtraditional.

Even with two warnings enabled, the following program would complain.

/tmp $ cat main.c 
int main(int argc, char **argv) {
    return 0;
}
/tmp $ gcc -Wstrict-prototypes -Wtraditional main.c 
main.c: In function ‘main’:
main.c:1:5: warning: traditional C rejects ISO C style function definitions [-Wtraditional]
 int main(int argc, char **argv) {
     ^

You may think "well, I'm going to use old style prototypes then". Nope, this won't work.

/tmp $ cat main.c 
int main(argc, argv)
    int argc;
    char **argv;
{
    return 0;
}
/tmp $ gcc -Wstrict-prototypes -Wtraditional main.c 
main.c:1:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 int main(argc, argv)
     ^

And no, not specifying any prototype is also wrong, as the compiler will also complain.

/tmp $ cat main.c 
int main() {
    return 0;
}
/tmp $ gcc -Wstrict-prototypes -Wtraditional main.c 
main.c:1:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 int main() {
     ^

If you define any functions inside your program, you cannot use all flags, because the compiler will complain about any imaginable function definition.

For C++, this is possible (the -Wtraditional flag doesn't exist), and very simple programs can be compiled. To enable all warnings, use following list of warnings (probably some warnings are duplicated, because I didn't bother to filter warnings enabled by -Wall).

-Wabi -Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder -Weffc++ -Wstrict-null-sentinel -Wno-non-template-friend -Wold-style-cast -Woverloaded-virtual -Wno-pmf-conversions -Wsign-promo -Wextra -Wall -Waddress -Waggregate-return -Warray-bounds -Wno-attributes -Wno-builtin-macro-redefined -Wc++0x-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wclobbered -Wcomment -Wconversion -Wcoverage-mismatch -Wno-deprecated -Wno-deprecated-declarations -Wdisabled-optimization -Wno-div-by-zero -Wempty-body -Wenum-compare -Wno-endif-labels -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 -Wno-format-contains-nul -Wno-format-extra-args -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wignored-qualifiers -Winit-self -Winline -Wno-int-to-pointer-cast -Wno-invalid-offsetof -Winvalid-pch -Wunsafe-loop-optimizations -Wlogical-op -Wlong-long -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn -Wno-mudflap -Wno-multichar -Wnonnull -Wno-overflow -Woverlength-strings -Wpacked -Wpacked-bitfield-compat -Wpadded -Wparentheses -Wpointer-arith -Wredundant-decls -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wsign-conversion -Wstack-protector -Wstrict-aliasing=1 -Wstrict-overflow=5 -Wswitch -Wswitch-default -Wswitch-enum -Wsync-nand -Wsystem-headers -Wtrigraphs -Wtype-limits -Wundef -Wuninitialized -Wunknown-pragmas -Wno-pragmas -Wunreachable-code -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value -Wunused-variable -Wvariadic-macros -Wvla -Wvolatile-register-var -Wwrite-strings
Hubbub answered 21/12, 2013 at 16:30 Comment(3)
I never bothered to check this until now, but actually, it's not impossible... try int main(int, char **); int main(argc, argv) int argc; char **argv; { (void)argc; (void)argv; return 0; }Natascha
Even with this trivial program I can still get "warning: stack usage is 16 bytes [-Wstack-usage=]" ;-)Sloat
OP stated somewhere that the purpose was to learn about style rules and to better inform the choice of what warnings to activate and what changes to make in the code.Maricamarice
N
12

Someone has created a set of tools for determining the complete set of warnings for a given GCC or Clang version.

For GCC, copying from the full list of warnings provided by this tool for your compiler version appears to be the only way to ensure that all warnings are turned on, since (unlike Clang) GCC does not provide -Weverything.

The tool appears to parse the actual c.opt file in the GCC source code, so its results should be definitive.

The repository also contains text files with the warning lists generated for most GCC and Clang versions (currently Clang 3.2 through 3.7 and GCC 3.4 through 5.3).

Nigercongo answered 28/2, 2016 at 19:4 Comment(1)
This is the answer. Use the "top level" list, and add all the arguments that are on the top level (not indented/nested). github.com/Barro/compiler-warnings/blob/master/gcc/…Ectomorph
C
8

GCC 4.3+ now has -Q --help=warnings, and you can even specify --help=warnings,C to just print out the C related warnings.

I just wrote an m4 module to take advantage of this (it also supports Clang's -Weverything); see wget_manywarnings.m4.

How to use it is pretty simple. Basically, the module turns every warn flag on. And you remove warnings as needed—some are really very verbose.

Example: configure.ac

If you don't use autotools, you'll find the code to turn on all disabled warnings in the m4 module, which basically is the GCC call piped through AWK:

flags="-Wall -Wextra -Wformat=2 "$(gcc -Wall -Wextra -Wformat=2 -Q --help=warning,C|awk '{ if (($2 == "[disabled]" || $2 == "") && $1!~/=/ && $1~/^-W/&& $1!="-Wall") print $1 }'

Cinch answered 11/11, 2016 at 21:32 Comment(0)
H
6

EDIT 2023: refreshed for GCC 12.


I gathered information from the other postings and one-by-one tested the warnings in the test for a C++ library.

Using the list from Haatschii and his/her method of getting the full list for 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.

Take into account, that:

  1. Some of these warnings are by default already turned on without adding any option.
  2. I don't claim to know what some warnings actually mean.
  3. I don't recommend using or not using any particular warning.
  4. Some are commented, and that doesn't mean anything. Comment or uncomment them as you need. (I commented the ones that were not useful for my project.)
  5. Some will not work on GCC 10.
  6. The list is given as-is, it may contain errors or typos.

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.

Now the list:

target_compile_options(
    target
    PRIVATE
        $<$<AND:$<CXX_COMPILER_ID:GNU>,$<NOT:$<CUDA_COMPILER_ID:NVIDIA>>,$<NOT:$<CUDA_COMPILER_ID:Clang>>>:
            -Werror
            -Wall
            -Wextra  # (activates -Wunknown-pragmas)
            -Wpedantic
            -WNSObject-attribute  # (gcc 12, not in 11)
            # -Wabi=13 -Wabi-tag (maybe important when linking with very old libraries)
            # -Wabsolute-value  # C/ObjC only (gcc 12, not in 11)
            -Waddress
            # -Waddress-of-packed-member (gcc 11, not in gcc 8)
            # -Waggregate-return (disallow return classes or structs, seems a C-compatibility warning)
            -Waggressive-loop-optimizations
            # -Waligned-new=all  (gcc 12, not in 11)
            # -Walloc-size-larger-than=<bytes>  (gcc 12, not in 11)
            -Walloc-zero  # -Walloc-size-larger-than=<bytes>
            -Walloca  # -Walloca-larger-than=<number>
            # -Wanalyzer-double-fclose -Wanalyzer-double-free -Wanalyzer-exposure-through-output-file -Wanalyzer-file-leak -Wanalyzer-free-of-non-heap -Wanalyzer-malloc-leak (gcc 11, not in gcc 9)
            # -Wanalyzer-mismatching-deallocation (gcc 11, not in gcc 10)
            # -Wanalyzer-null-argument -Wanalyzer-possible-null-argument -Wanalyzer-null-dereference (gcc 11, not in gcc 9)
            # -Wanalyzer-possible-null-dereference (gcc 11, not in gcc 9)
            # -Wanalyzer-shift-count-negative -Wanalyzer-shift-count-overflow (gcc 11, not in gcc 10)
            # -Wanalyzer-stale-setjmp-buffer
            # -Wanalyzer-tainted-allocation-size (gcc 12, not in 11)
            # -Wanalyzer-tainted-array-index (gcc 11, not in gcc 9)
            # -Wanalyzer-tainted-divisor -Wanalyzer-tainted-offset -Wanalyzer-tainted-size -Wanalyzer-too-complex -Wanalyzer-unsafe-call-within-signal-handler (gcc 12, not in 11)
            # -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 (gcc 11, not in gcc 10)
            # -Warith-conversion (gcc 11, not in gcc 9)
            -Warray-bounds
            # -Warray-bounds=<0,2> -Warray-compare (gcc 12, not in gcc 9)
            # -Warray-parameter -Warray-parameter=<0,2>  (gcc 11, not in gcc 10)
            # -Wattribute-alias -Wattribute-alias=<0,2> (gcc 12, not in 11)
            # -Wattribute-warning (gcc 9, not in 8)
            -Wattributes
            # -Wbad-function-cast (gcc 12, not in 11)
            -Wbool-compare -Wbool-operation
            # -Wbidi-chars -Wbidi-chars=any (gcc 12, not in 11)
            -Wbuiltin-declaration-mismatch -Wbuiltin-macro-redefined
            #-Wc++-compat
            -Wc++0x-compat -Wc++11-compat -Wc++14-compat -Wc++17-compat -Wc++17-extensions -Wc++1z-compat
            # -Wc++20-compat -Wc++20-extensions -Wc++23-extensions -Wc++2a-compat (gcc 11, not in gcc 9)
            # -Wcannot-profile (gcc 9, not in gcc 8)
            -Wcast-align=strict -Wcast-function-type
            -Wcast-qual
            -Wcatch-value  #=<0, 3>
            -Wchar-subscripts
            # -Wchkp -Wclass-conversion -Wclass-memaccess (gcc 12, not in 11)
            # -Wclobbered
            # -Wcomma-subscript (gcc 12, not in 11)
            # -Wcomment  # (same as -Wcomments)
            # -Wcompare-reals (gcc 12, not in 11)
            -Wconditionally-supported
            -Wconversion -Wconversion-null
            -Wcoverage-mismatch -Wcpp
            # -Wctad-maybe-unsupported  # TODO(correaa) add ctad explicitly as necessary
            -Wctor-dtor-privacy
            -Wdangling-else
            # -Wdangling-pointer (gcc 12, not in 11)
            -Wdate-time
            # -Wdeclaration-after-statement (gcc 12, not in 11)
            -Wdelete-incomplete -Wdelete-non-virtual-dtor
            -Wdeprecated
            # -Wdeprecated-copy -Wdeprecated-copy-dtor (gcc 11, not in gcc 8)
            -Wdeprecated-declarations
            # -Wdeprecated-enum-enum-conversion -Wdeprecated-enum-float-conversion (gcc 11, not in gcc 10)
            # -Wdesignated-init (gcc 12, not in 11)
            -Wdisabled-optimization
            # -Wdiscarded-array-qualifiers (gcc 12, not in 11)
            -Wdiv-by-zero -Wdouble-promotion
            # -Wduplicate-decl-specifier (gcc 12, not in 11)
            -Wduplicated-branches -Wduplicated-cond
            # -Weffc++ (doesn't allow some advanced techniques, such as CRTP)
            -Wempty-body -Wendif-labels
            -Wenum-compare
            # -Wenum-conversion (gcc 11, not in gcc 10)
            -Wexpansion-to-defined
            # -Werror-implicit-function-declaration not for C++ (gcc 12, not in 11)
            # -Wexceptions  (gcc 11, not in gcc 10)
            # -Wextra
            -Wextra-semi
            -Wfloat-conversion # -Wfloat-equal (disallows float equality)
            -Wformat=2
            # -Wformat-contains-nul (gcc 12, not in 11)
            # -Wformat-diag (gcc 10, not in gcc 9)
            -Wformat-extra-args -Wformat-nonliteral
            # -Wformat-overflow=1
            -Wformat-security -Wformat-signedness -Wformat-truncation -Wformat-y2k -Wformat-zero-length
            -Wframe-address  # -Wframe-larger-than=<byte-size>
            -Wfree-nonheap-object -Whsa
            -Wif-not-aligned
            -Wignored-attributes -Wignored-qualifiers
            # -Wimplicit (gcc 12, not in 11)
            -Wimplicit-fallthrough#=3  # -Wimplicit-fallthrough=<0,5>
            # -Wimplicit-function-declaration -Wimplicit-int (gcc 12, not in 11)
            # -Winaccessible-base (gcc 12, not in 11)
            # -Wincompatible-pointer-types -Winfinite-recursion  -Winherited-variadic-ctor -Winit-list-lifetime (gcc 12, not in 11)
            -Winit-self
            # -Winline
            # -Wint-conversion (gcc 12, not in 11)
            -Wint-in-bool-context -Wint-to-pointer-cast
            # -Winterference-size (gcc 12, not in 11)
            # -Winvalid-imported-macros (gcc 11, not in gcc 10)
            -Winvalid-memory-model -Winvalid-offsetof -Winvalid-pch
            # -Wjump-misses-init (gcc 12, not in 11)
            # -Wlarger-than=<byte-size>  # (disallow large objects types? in executable)
            -Wliteral-suffix
            -Wlogical-not-parentheses -Wlogical-op
            # -Wlong-long (C++98 warning)
            -Wlto-type-mismatch -Wmain -Wmaybe-uninitialized
            -Wmemset-elt-size -Wmemset-transposed-args
            -Wmisleading-indentation
            # -Wmismatched-dealloc -Wmismatched-new-delete (gcc 11, not in gcc 10)
            # -Wmismatched-tags (gcc 11, not in gcc 9)
            -Wmissing-attributes
            -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn
            # -Wmissing-parameter-type (gcc 12, not in  11)
            # -Wmissing-profile (gcc 11, not in gcc 8)
            # -Wmissing-prototypes -Wmissing-requires -Wmissing-template-keyword (gcc 12, not in 11)
            -Wmultichar
            # -Wmultiple-inheritance (disallows composition by inheritance)
            -Wmultistatement-macros
            # -Wnamespaces (disallows use of namespaces, seems a C-tool)
            -Wnarrowing
            # -Wnested-externs (gcc 12, not in 11)
            # -Wno-alloc-size-larger-than=<bytes> -Wframe-larger-than=<bytes> -Wno-larger-than<bytes> -Wstack-usage=<bytes> (gcc 112, not in 11)
            -Wnoexcept -Wnoexcept-type
            -Wnon-template-friend -Wnon-virtual-dtor
            -Wnonnull -Wnonnull-compare
            -Wnormalized  #=nfc -Wnormalized=[none|id|nfc|nfkc]
            -Wnull-dereference
            -Wodr -Wold-style-cast
            # -Wold-style-declaration -Wold-style-definition (gcc 12, not in 11)
            # -Wopenacc-parallelism (gcc 12, not in 11)
            -Wopenmp-simd -Woverflow
            -Woverlength-strings -Woverloaded-virtual
            # -Woverride-init -Woverride-init-side-effects (gcc 12, not in 11)
            -Wpacked -Wpacked-bitfield-compat -Wpacked-not-aligned
            # -Wpadded (disallows structs that need padding for alignment)
            -Wparentheses
            # -Wpedantic (see above)
            # -Wpessimizing-move (gcc 11, not in gcc 8)
            -Wplacement-new  #=1  -Wplacement-new=<0,2>
            -Wpmf-conversions
            -Wpointer-arith -Wpointer-compare
            # -Wpointer-sign -Wpointer-to-int-cast (gcc 12, not in 11)
            -Wpragmas
            # -Wprio-ctor-dtor (gcc 11, not in gcc 8)
            -Wpsabi
            # -Wrange-loop-construct (gcc 11, not in gcc 10)
            -Wredundant-decls
            # -Wredundant-move (gcc 11, not in gcc 8)
            # -Wredundant-tags (gcc 11, not in gcc 9)
            -Wregister
            # -Wreorder (gcc 12, not in 11)
            -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 (gcc 11, not in gcc 10)
            -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>
            # -Wstrict-prototypes (gcc 12, not in gcc 11)
            # -Wstring-compare (gcc 11, not in gcc 9)
            -Wstringop-overflow  #=2  -Wstringop-overflow=<0,4>
            # -Wstringop-overread (gcc 11, not in gcc 10)
            -Wstringop-truncation
            -Wsubobject-linkage
            # -Wsuggest-attribute=cold (gcc 12, not in 11)
            -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-attribute=malloc -Wsuggest-attribute=noreturn
            # -Wsuggest-attribute=pure
            -Wsuggest-final-methods -Wsuggest-final-types
            # -Wsuggest-override (gcc 12, not in gcc 11)
            -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-enum
            # -Wswitch-outside-range (gcc 11, not in gcc 9)
            -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)
            # -Wterminate -Wtraditional -Wtraditional-conversion (gcc 12, not in 11)
            -Wtrampolines -Wtrigraphs
            # -Wtrivial-auto-var-init (gcc 12, not in 11)
            # -Wtsan (gcc 11, not in 10)
            -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
            # -Wunsuffixed-float-constants (gcc 12, not in 11)
            -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable
            # -Wunused-const-variable  #=2 TODO(correaa) add [[maybe_unused]] to niebloids
            -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable
            # -Wuse-after-free  # =<0,3> (gcc 12, not in 11)
            -Wuseless-cast
            -Wvarargs -Wvariadic-macros -Wvector-operation-performance
            # -Wvexing-parse (gcc 11, not in gcc 10)
            -Wvirtual-inheritance -Wvirtual-move-assign
            -Wvla
            # -Wvla-larger-than=<number>  (gcc 12, not in 11)
            # -Wvla-parameter (gcc 11, not in gcc 10)
            # -Wvolatile (gcc 11, not in gcc 9)
            -Wvolatile-register-var
            -Wwrite-strings
            -Wzero-as-null-pointer-constant
            # -Wzero-length-bounds (gcc 12, not in 11)
        >
)
Houle answered 20/4, 2022 at 7:59 Comment(2)
I wrote a little cmake project that has this stuff for clang/gcc up to release versions: github.com/goldsteinn/weverythingSuperadd
@Noah, very cool, and it seems that you can selective activate the flags depending on the version, which is a big limitation of my hardcoded list. I have to comment flags when going to older version.Houle
L
4

From this page:

Note that some warning flags are not implied by -Wall. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to modify the code to suppress the warning. Some of them are enabled by -Wextra but many of them must be enabled individually.

I guess the question is which ones? Perhaps you could grep that page for all lines beginning with -W, and get a complete list of warning flags. Then compare those with the lists under -Wall and -Wextra. There is also -Wpedantic, though you are obviously wanting to be even more pedantic still =)

Lonnalonnard answered 30/7, 2012 at 3:0 Comment(3)
"And I still have no idea if this list is comprehensive" ... yes, I can certainly grep that page, but the question is, is it comprehensive?Natascha
I don't know... You might have to pour through the GCC source code. Are you trying to make your life as a programmer exceedingly difficult, or is there a good reason why you want to see every conceivable warning? =)Lonnalonnard
I'd like to see GCC's diagnosis of my code -- I find it to be really helpful. But obviously, if I already knew about all the warnings and which ones are useful (and which ones aren't), then there would've been nothing to ask. There's no real way for me to tell unless I try them (and e.g. I found the shadowing one helpful, so it's not like they're useless just because they're turned off).Natascha
E
3

And I still have no idea if this list is comprehensive.

It probably is, but the only list that is 100% comprehensive is the actual source for the compiler. However, GCC is big! And I don't know if all command-line parameters are collected in one place or spread out over several source files. Also note that some warnings are for the pre-processor, some for the actual compiler and some for the linker (which is a completely separate program, and found in the binutils package) so they most likely are spread out.

Emulous answered 30/7, 2012 at 6:3 Comment(1)
I linked to the Options Summary page in my answer, which groups all options into one page. GCC code review policies do not allow new options without documentation, so the docs should be comprehensive.Mainsail

© 2022 - 2024 — McMap. All rights reserved.