110

-o changes the output filename (I found that using --help)

But I can't find out what -Wall does?

8
  • 8
    "man gcc" on your console tells you everything about this flag and a simple google search with "gcc -Wall" as well... Mar 9, 2010 at 9:59
  • As a general tip, try reading the man entries for programs if you want to know what a switch does, or what switches are available. The man page of gcccan be read on linux.die.net/man/1/gcc - you can do a quick search there for the text "-Wall"
    – gnud
    Mar 9, 2010 at 10:00
  • 8
    @David Sauter, Google will not find anything with "-wall". It will exclude all "wall" from search. Mar 9, 2010 at 10:01
  • @Kirill Not if you use quotes, like I'm guessing David mean
    – gnud
    Mar 9, 2010 at 10:01
  • 1
    // , I always thought it was an homage to Larry Wall. Sep 4, 2015 at 17:34

7 Answers 7

124

It's short for "warn all" -- it turns on (almost) all the warnings that g++ can tell you about. Typically a good idea, especially if you're a beginner, because understanding and fixing those warnings can help you fix lots of different kinds of problems in your code.

4
  • 26
    More warnings (some of which are pretty useful) can be turned on with -Wextra and -pedantic.
    – gnud
    Mar 9, 2010 at 9:58
  • 10
    It's not (almost) all. It's actually only a very small fraction of the available warnings. It's the ones that "all" agree upon. The really good idea is to do -Wall -Wextra, and then peruse the manual to find as many more warnings you could enable as possible, because even -Wextra is only a small subset...
    – DevSolar
    Feb 25, 2014 at 8:20
  • @DevSolar very good point. Do you know if there's a flag that means "literally all the warnings"?
    – Tyler
    Feb 26, 2014 at 0:32
  • 1
    @MatrixFrog: Unfortunately, there is no such option, at least not for the compilers I know of. And the list of available warnings changes over time... if the GCC team hadn't disabled -Wunreachable-code some time back, Apple would be much happier these days. ;-)
    – DevSolar
    Feb 26, 2014 at 6:16
47

See man gcc.

-Wall turns on these warnings:

-Waddress -Warray-bounds (only with -O2) -Wc++0x-compat -Wchar-subscripts
-Wenum-compare (in C/Objc; this is on by default in C++) -Wimplicit-int (C and
 Objective-C only) -Wimplicit-function-declaration (C and Objective-C only) 
-Wcomment -Wformat -Wmain (only for C/ObjC and unless -ffreestanding) 
-Wmissing-braces -Wnonnull -Wparentheses -Wpointer-sign -Wreorder -Wreturn-type 
-Wsequence-point -Wsign-compare (only in C++) -Wstrict-aliasing 
-Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas 
-Wunused-function -Wunused-label -Wunused-value -Wunused-variable 
-Wvolatile-register-var

-Wextra contains:

-Wclobbered -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers
-Wmissing-parameter-type (C only) -Wold-style-declaration (C only) -Woverride-init
-Wsign-compare -Wtype-limits -Wuninitialized -Wunused-parameter (only with -Wunused
 or -Wall) -Wunused-but-set-parameter (only with -Wunused or -Wall)

There are many more warnings which you have to turn on explicitly.

E.g. for our C code we use:

-Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wdisabled-optimization -Wdiv-by-zero -Wendif-labels -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-y2k -Wimplicit -Wimport -Winit-self -Winline -Winvalid-pch -Wjump-misses-init -Wlogical-op -Werror=missing-braces -Wmissing-declarations -Wno-missing-format-attribute -Wmissing-include-dirs -Wmultichar -Wpacked -Wpointer-arith -Wreturn-type -Wsequence-point -Wsign-compare -Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-default -Werror=undef -Wno-unused -Wvariadic-macros -Wwrite-strings -Wc++-compat -Werror=declaration-after-statement -Werror=implicit-function-declaration -Wmissing-prototypes -Werror=nested-externs -Werror=old-style-definition -Werror=strict-prototypes

or just the set of warnings with https://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html

1
  • FWIW an even more authoritative source is (duh) the source code. You can see what gets pulled in by searching for LangEnabledBy or EnabledBy.
    – mirh
    Aug 4 at 12:07
25

Sadly enough none of the answers is quoting the actually relevant part of manual, which really brings it to a point:

This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros.

[...]

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.

Ergo:

  • -Wall does not mean "all warnings".
  • It does also not mean "(almost) all", not by a long shot.
  • It does mean a set of individual options that is bound to change.

Bottom line, it is about the absolute minimum of warnings you should set. While -Wall -Wextra is better, it's still not making use of all the error checking your compiler can do for you.


Personally I wouldn't go for less than -Wall -Wextra -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wmissing-declarations -Wredundant-decls -Wshadow -Woverloaded-virtual. All my current projects actually use a list of warnings longer than that (without triggering any of them). And I do check the manual on every major release for new options. The compiler is your friend. Use whatever diagnostics it can offer you.

2
  • I have started to learn programming using C++. I am using programming principles and practice using cpp. My system is ubuntu 16.04, I use vscode as my editor. Do you recommend me to use your -Wall -Wextra -Wfloat-equal -Wundef -Wcast-align -Wwrite-strings -Wlogical-op -Wmissing-declarations -Wredundant-decls -Wshadow -Woverloaded-virtual while I compile with g++ -std=c++11 while I learn c++ and programming? Or should I skip this part and start using error messages flags later on? If so when should I start with the error messages? May 9, 2018 at 21:18
  • 3
    @vkv: I believe that the compiler is really your friend, and you should take advantage of every little bit of good advice it can give you.
    – DevSolar
    May 10, 2018 at 21:13
6

It enables warnings which are deemed useful and easy to avoid at the source by gcc writers. There is also -W (-Wextra in newer releases) which are deemed useful but for which work-arounding false positives can be difficult or result in clumsy code.

gcc has also a bunch of other warnings, generally less useful. See http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Warning-Options.html#Warning-Options

2

It enables most warning messages.

You can find out more if you use g++ --help=warnings.

0

It enables all warnings. (reads as "Warning All")

2
  • There are actually a lot of warnings it doesn't enable (such as nonvirtual dtor in a class with virtual methods).
    – Mark B
    Mar 9, 2010 at 15:28
  • see Yuval's answer: -Wall just means "most warnings" instead of "all warnings".
    – ChrisZZ
    Jan 28, 2020 at 14:17
-1

It shows all warnings. I'd recommend also use -pedantic to warn about some non-conformant parts of code.

5
  • For gcc doc: "Some users try to use -pedantic to check programs for strict ISO C conformance. They soon find that it does not do quite what they want: it finds some non-ISO practices, but not all—only those for which ISO C requires a diagnostic, and some others for which diagnostics have been added." Mar 9, 2010 at 10:14
  • It doesn't give 100% guarantee, but it helps. Mar 9, 2010 at 11:23
  • 1
    If you hadn't written some instead of all in "to warn about all non-conformant parts", I wouldn't have commented. But your current formulation just spread the misconception the gcc documentation warn against. Mar 9, 2010 at 12:13
  • Fixed. But in practice it is rather looks like a "most of" and not "some". Mar 9, 2010 at 13:05
  • gcc should deprecate that flag's name and use a different flag if it doesn't imply all warnings.
    – Sohail Si
    Jun 13 at 13:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.