Make one gcc warning an error?

前端 未结 5 1683
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 15:37

I get this warning from GCC:

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

相关标签:
5条回答
  • 2020-12-14 16:20

    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.

    0 讨论(0)
  • 2020-12-14 16:23

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

    0 讨论(0)
  • 2020-12-14 16:30

    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.

    0 讨论(0)
  • 2020-12-14 16:30

    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.

    0 讨论(0)
  • 2020-12-14 16:33

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

    0 讨论(0)
提交回复
热议问题