public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* -Wold-style-casts and system headers
@ 2013-06-18 16:14 Anthony Foiani
  2013-06-18 16:42 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Anthony Foiani @ 2013-06-18 16:14 UTC (permalink / raw)
  To: gcc-help


Greetings.

I'm using -Wold-style-casts on my project, and I've found that I get
warnings in my code when certain macros are expanded.

These macros are defined in headers under /usr/include; my reading of
the manual is that these ought to get some immunity from some
warnings:

  "Macros defined in a system header are immune to a few warnings
  wherever they are expanded. This immunity is granted on an ad-hoc
  basis, when we find that a warning generates lots of false positives
  because of code in macros defined in system headers."
  -- http://gcc.gnu.org/onlinedocs/cpp/System-Headers.html

But it seems there is some degree of judgment ("ad-hoc basis")
involved -- it's not clear whether that's regarding the header files,
individual macros, or individual warnings.

The case I hit today was from zlib.h, which has the following macro
definition:

  #define deflateInit(strm, level) \
          deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))

When expanded into my sample code:

  // https://gist.github.com/tkil/5806218

  #include <string.h>
  #include <zlib.h>

  int main()
  {
      z_stream_s strm;
      memset( &strm, 0, sizeof( strm ) );
      const int rc = deflateInit( &strm, Z_DEFAULT_COMPRESSION );
      return rc;
  }

I got:

  $ g++ -Wold-style-cast -o g++-warnings-check g++-warnings-check.cpp -lz
  g++-warnings-check.cpp: In function ‘int main()’:
  g++-warnings-check.cpp:49:20: warning: use of old-style cast [-Wold-style-cast]

A few months ago, I ran into this <sys/select.h> as well; in that
case, I could easily enough rewrite the needed operations for private
use, so I did so.

I'm aware that I can disable that warning for the single file, or even
for a single region in the file using pragmas, but I would like to
understand why g++ isn't applying the "system header" rule to that
macro.

Best regards,
Anthony Foiani

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-18 17:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-18 16:14 -Wold-style-casts and system headers Anthony Foiani
2013-06-18 16:42 ` Jonathan Wakely
2013-06-18 16:57   ` Anthony Foiani
2013-06-18 17:02     ` Anthony Foiani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).