views:

1093

answers:

5

I get this warning from GCC:

warning: cannot pass objects of non-POD type 'class Something' through '...'; call will abort at runtime

It's pretty deadly, especially since it calls an abort. Why isn't this an error? I would like to make it an error, but:

  1. How do I make a specific warning an error?
  2. Which warning is it? According to http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html, -Wno-invalid-offsetof looks like the flag to hide it, but it doesn't
+4  A: 

I'm not sure what the correct warning is, but once you've found it, you can change it's disposition with the following (using 'format' as the example):

#pragma GCC diagnostic error "-Wformat"

Or as strager points out:

gcc -Werror=format ...

Edit: I've just checked the gcc source for this and this specific warning cannot be disabled via command line flags.

Sean Bright
+3  A: 

You can use the -Werror compiler flag to turn all or some warnings into errors.

strager
+4  A: 

Sounds like there are a bunch of other warnings that you don't want to be turned into errors (using the -Werror flag). In general, its good practice to fix all warnings. Using -Werror forces this.

Stephen Doyle
Amen, your code should be warning-free with at least -Wall (although some of the stuff that -Wextra reports are excusable, e.g. unused variables/parameters).
Adam Rosenfield
You can do -Wall -Wextra -Wno-unused-parameters -Wno-unused-functions ... Any specific warning can be disabled with the -Wno-$foo syntax, which makes it easy to excuse the specifics. Unfortunately, it doesn't help with any subset of the -pedantic warnings.
Tom
+2  A: 

-Werror=specific-warning will turn the specified -Wspecific-warning into an error in GCC 4.3.x or newer. In 4.1.2, only -Werror-implicit-function-declaration works. Note the hyphen instead of equals sign -- it works for that specific case only and no others. This is one of the more serious common warnings and it's definitely handy to make it into an error.

Apart from that, older versions of GCC only seem to provide the -Werror sledgehammer of making every last warning an error.

J Barlow
+2  A: 

You can use -fdiagnostics-show-option to see the -W option that applies to a particular warning.

Unfortunately, in this case there is no specific option that covers that warning.

It appears that there will be better support for this in gcc-4.5.

Jonathan