Warning options of GCC

The GCC and G++ compilers have many warning options that can be useful to improve the quality of your code. All the warning options are listed and described here.

Since the list of warnings is very long, GCC provides a few warning options that are a shortcut for enabling a larger bunch of warnings. These warning options are -Wall, -Wextra and -Wpedantic.

The warnings enabled by -Wall and -Wextra is listed along with their description. However, this is not provided for -Wpedantic. I went through the individual warning descriptions and found the warning options enabled by -Wpedantic:

Warning options enabled by -Wpedantic:

-Wpointer-arith
-Wlong-long
-Wvariadic-macros
-Wvla
-Woverlength-strings

It can very useful to know which of the warning options are not enabled by -Wall, -Wextra and -Wpedantic. These are the options that might be useful for debugging or improving particular problems with your code. Again, I went through the individual warning descriptions and here they are:

Warning options not included by -Wall, -Wextra and -Wpedantic:

-Wdouble-promotion
-Wmissing-include-dirs
-Wswitch-default
-Wswitch-enum
-Wswitch-bool
-Wsync-nand
-Wsuggest-attribute=[pure|const|noreturn|format]
-Wsuggest-final-types
-Wsuggest-final-methods
-Wsystem-headers
-Wtrampolines
-Wfloat-equal
-Wtraditional
-Wtraditional-conversion
-Wdeclaration-after-statement
-Wundef
-Wshadow
-Wlarger-than=len
-Wframe-larger-than=len
-Wstack-usage=len
-Wunsafe-loop-optimizations
-Wbad-function-cast
-Wc90-c99-compat
-Wc99-c11-compat
-Wc++-compat
-Wcast-qual
-Wcast-align
-Wwrite-strings
-Wconditionally-supported
-Wconversion
-Wzero-as-null-pointer-constant
-Wdate-time
-Wdelete-incomplete
-Wuseless-cast
-Wjump-misses-init
-Wsign-conversion
-Wfloat-conversion
-Wlogical-op
-Waggregate-return
-Wstrict-prototypes
-Wold-style-definition
-Wmissing-prototypes
-Wmissing-declarations
-Wnormalized[=<none|id|nfc|nfkc>]
-Wpacked
-Wpadded
-Wredundant-decls
-Wnested-externs
-Winline
-Winvalid-pch
-Wvector-operation-performance
-Wdisabled-optimization
-Wstack-protector
-Wunsuffixed-float-constants

Note that I have not included the warning options that disable certain types of warning messages.

Finally, here is the list of warnings that I like to compile with:

-Wall
-Wextra
-Wpedantic
-Wconversion
-Wmissing-include-dirs

Tried with: GCC 5.0.0 online documentation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s