Make one gcc warning an error?

馋奶兔 提交于 2019-12-17 23:34:25

问题


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

回答1:


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.




回答2:


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




回答3:


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.




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/475407/make-one-gcc-warning-an-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!