From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30945 invoked by alias); 18 Jun 2013 16:14:57 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 30911 invoked by uid 89); 18 Jun 2013 16:14:51 -0000 X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from scrye.com (HELO mail.scrye.com) (75.148.32.185) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 18 Jun 2013 16:14:50 +0000 Received: by mail.scrye.com (Postfix, from userid 19) id B597E658A41; Tue, 18 Jun 2013 10:14:48 -0600 (MDT) To: gcc-help@gcc.gnu.org Subject: -Wold-style-casts and system headers From: Anthony Foiani Reply-To: Anthony Foiani Date: Tue, 18 Jun 2013 16:14:00 -0000 Message-ID: User-Agent: Gnus/5.101 (Gnus v5.10.10) XEmacs/21.5-b33 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-7 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2013-06/txt/msg00131.txt.bz2 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 #include int main() { z_stream_s strm; memset( &strm, 0, sizeof( strm ) ); const int rc =3D 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 =A1int main()=A2: g++-warnings-check.cpp:49:20: warning: use of old-style cast [-Wold-style= -cast] A few months ago, I ran into this 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