Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Warning options of GCC

📅 2014-Oct-24 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ gcc, warning ⬩ 📚 Archive

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.

-Wall and -Wextra

The warnings enabled by -Wall and -Wextra is listed along with their description.

-Wpedantic

A list of warnings enabled by -Wpedantic is not provided in the documentation. I went through the individual warning descriptions and found the warning options enabled by -Wpedantic:

Warning options enabled by -Wpedantic:

-Wexpansion-to-defined
-Wlong-long
-Wmain
-Woverlength-strings
-Wpointer-arith
-Wpointer-sign
-Wvariadic-macros
-Wvla

Warnings not in -Wall, -Wextra or -Wpedantic

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:

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

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

Warnings I use

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

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

References