Automake - How to enable compiler warnings

57 Views Asked by At

I was instructed that the current Automake file disables some warnings, and we want full warnings in our build...

This is the relevant Automake lines.

AM_CXXFLAGS = -std=c++14    
AM_CXXFLAGS += -Wno-memset-elt-size    
AM_CXXFLAGS += -faligned-new    
AM_CXXFLAGS += -DXSD_CXX11    
AM_CXXFLAGS += -Wno-stringop-truncation    
AM_CXXFLAGS += -Wno-stringop-overflow    
AM_CXXFLAGS += -Wno-int-in-bool-context    
AM_CXXFLAGS += -D_FILE_OFFSET_BITS=64    
AM_CXXFLAGS += -D_REENTRANT    
AM_CXXFLAGS += -D__STDC_FORMAT_MACROS    
AM_CXXFLAGS += -fPIC    
AM_CXXFLAGS += -fmessage-length=0    
AM_CXXFLAGS += -Wall    
AM_CXXFLAGS += -Wsign-compare    
AM_CXXFLAGS += -Wfloat-equal    
AM_CXXFLAGS += -Wno-unused-label    
AM_CXXFLAGS += -Wshadow

I have difficulty finding documentation for all these gcc flags. Can someone tell me what lines should I remove, in order to have full warnings in the build?

1

There are 1 best solutions below

0
ndim On

You have -Wall and a few -Wfoo and a few -Wno-foo arguments.

  • -Wall enables a certain set of warnings
  • -Wfoo enables the foo warning
  • -Wno-foo disables the foo warning

So as it stands, you have the -Wall set of warnings enabled plus some others and minus some others.

Somewhat counterintuitively, some -DFOO and -ffoo arguments enable extra compiler functions which are in turn required for producing some warnings.

If you want "all" warnings, you need to consult your specific compiler version's documentation and read up on all the warnings, the warnings enabled by -Wall which is NOT all of them, and what other warnings the compiler offers.

On gcc, -pedantic can additionally enable language lawyer type warnings and -Wextra enables many warnings which are not included in -Wall.

Why only many warnings? Some warnings need special -f arguments activating specific compiler features which are needed for that warning.

The clang compilers also work with -pedantic, -Wall and -Wextra, but they have -Wmost as well.

Note that clang's -Weverything is for testing the clang compiler, not for compiling code. Some warnings in -Weverything can be mutually exclusive, i.e. either some program code produces either warning A or warning B, and there is no way to write the code to produce neither.

I personally like the compiler to produce as many warnings as I can reasonably enable, and therefore I use -pedantic -Wall -Wextra with gcc and add -Wmost on clang.

OK, and I make every warning an error using -Werror, but that exceeds the scope of this question.