Question

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
Was it helpful?

Solution

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.

OTHER TIPS

-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.

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.

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top