Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended -W flags for building C++ with gcc

I was looking for a list of recommended g++ warning options for C++ and only could find this: Recommended gcc warning options for C and Useful GCC flags for C which are all quite C specific

-Wall and -Wextra enable most but not all of the warnings gcc can generate.

Which warnings that aren't enabled by those options especially when compiling C++ should be turned on as well?

like image 908
pmr Avatar asked Mar 12 '11 16:03

pmr


2 Answers

-Wall -Wextra tends to cover the really noteworthy ones. Personally, I also like to compile with -ansi -pedantic and occasionally -Wshadow.

Also, it can be a little noisy and not useful 100% of the time, but -Weffc++ sometimes has good suggestions for better code quality as well.

EDIT In the age of modern C++, you should replace -ansi -pedantic with -std=c++14 -pedantic or whatever your version of choice is, since -ansi will put the compiler into C++98/C++-03 mode.

like image 128
Evan Teran Avatar answered Sep 20 '22 04:09

Evan Teran


Don't forget -Wstrict-aliasing.

I found this post was good, look the params up: Recommended gcc warning options for C

like image 21
stefan Avatar answered Sep 22 '22 04:09

stefan