Best GCC warning flags for compiling C++
July 18, 2014 [ACCU, C++, Programming, Tech]A recent discussion on ACCU-general gave people an opportunity to share the warning flags they like to use with g++.
I thought I'd write down the consensus as I understood it, mainly for my own reference:
-Wredundant-decls -Wcast-align -Wmissing-declarations -Wmissing-include-dirs -Wswitch-enum -Wswitch-default -Wextra -Wall -Werror -Winvalid-pch -Wredundant-decls -Wmissing-prototypes -Wformat=2 -Wmissing-format-attribute -Wformat-nonliteral
We were advised by Jonathan Wakely that -Weffc++ is not very useful since it is mostly based on the first edition of the book Effective C++, many of whose recommendations were improved in the second edition, and also apparently GCC doesn't do a great job of warning about them.
Update: thanks to an article[1] by Roger Orr in CVu these flags are highly recommended in GCC 5.2+:
-flto -Wodr
[1] Orr, Roger "One Definition Rule", in CVu Volume 27, Issue 5 p16 (editor: Steve Love)