5

In gcc -w is used to disable all warnings. However in this case I can't enable specific ones (e.g. -Wreturn-type).

Is it possible to disable all warnings, but enable few specific ones?

As a workaround, is there a way to generate list of all -Wno-xxx at once? And will it help? I wouldn't want to do this manually just to find out that it is not equal to -w.

4
  • 1
    That's odd. You usually should enable all warnings and disable specific ones... Commented Apr 6, 2012 at 9:42
  • 1
    Yes, you are right, you know better! But let's imagine that I have a legacy project with 4 mlns lines of code where I would like to find specific errors. Commented Apr 6, 2012 at 9:44
  • Well, if you just specify -Wreturn-type (no other warning-related flags), doesn't that do what you want? Commented Apr 6, 2012 at 9:47
  • No, there're warnings enabled by default. Commented Apr 6, 2012 at 9:51

1 Answer 1

2

You can use the following command to get an WARN_OPTS variable suitable for injecting directly into your Makefile:

gcc --help=warnings | awk ' BEGIN { print "WARN_OPTS = \\" } /-W[^ ]/ { print $1" \\"} ' | sed 's/^-W/ -Wno-/' >makefile.inject 

This gives you output (in makefile.inject) like:

WARN_OPTS = \ -Wno- \ -Wno-abi \ -Wno-address \ -Wno-aggregate-return \ -Wno-aliasing \ -Wno-align-commons \ -Wno-all \ -Wno-ampersand \ -Wno-array-bounds \ -Wno-array-temporaries \ : : : -Wno-variadic-macros \ -Wno-vector-operation-performance \ -Wno-vla \ -Wno-volatile-register-var \ -Wno-write-strings \ -Wno-zero-as-null-pointer-constant \ 

Once that's put in your actual Makefile, simply use $(WARN_OPTS) as part of your gcc command.

It may need a small amount of touch up to:

  • get rid of invalid options such as -Wno-;
  • fix certain -Wno-<key>=<value> types; and
  • remove the final \ character.

but that's minimal effort compared to the generation of the long list, something you can now do rather simply.

When you establish that you want one of those warnings, simply switch from the -Wno-<something> back to -W<something>.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.