public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Anthony Foiani <tkil@scrye.com>
To: gcc-help@gcc.gnu.org
Subject: -Wold-style-casts and system headers
Date: Tue, 18 Jun 2013 16:14:00 -0000	[thread overview]
Message-ID: <gip1b5rbb.fsf@dworkin.scrye.com> (raw)


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

             reply	other threads:[~2013-06-18 16:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18 16:14 Anthony Foiani [this message]
2013-06-18 16:42 ` Jonathan Wakely
2013-06-18 16:57   ` Anthony Foiani
2013-06-18 17:02     ` Anthony Foiani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gip1b5rbb.fsf@dworkin.scrye.com \
    --to=tkil@scrye.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).