* -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
* Re: -Wold-style-casts and system headers
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
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2013-06-18 16:42 UTC (permalink / raw)
To: Anthony Foiani; +Cc: gcc-help
On 18 June 2013 17:14, Anthony Foiani wrote:
>
>
> 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.
It's because the expansion of the macro is in your code, not in a system header.
There are some open bug reports on similar subjects
e.g.http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7263#c8
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: -Wold-style-casts and system headers
2013-06-18 16:42 ` Jonathan Wakely
@ 2013-06-18 16:57 ` Anthony Foiani
2013-06-18 17:02 ` Anthony Foiani
0 siblings, 1 reply; 4+ messages in thread
From: Anthony Foiani @ 2013-06-18 16:57 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: gcc-help
Jonathan --
Thanks for the quick reply.
Jonathan Wakely <jwakely.gcc@gmail.com> writes:
> On 18 June 2013 17:14, Anthony Foiani wrote:
>> 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.
>
> It's because the expansion of the macro is in your code, not in a
> system header.
If that's the expected behavior, then the manual probably needs
rephrasing:
"Macros defined in a system header are immune to a few warnings
wherever they are expanded."
I certainly expected "wherever" to include user code, and it seems
that's an important place for it to apply. An even shorter example:
#include <sys/select.h>
int main()
{
fd_set fds;
FD_CLR( 0, &fds );
return 0;
}
Generates:
$ g++ -Wold-style-cast -o g++-cast-warning g++-cast-warning.cpp
g++-cast-warning.cpp: In function ‘int main()’:
g++-cast-warning.cpp:47:5: warning: use of old-style cast [-Wold-style-cast]
g++-cast-warning.cpp:47:5: warning: use of old-style cast [-Wold-style-cast]
g++-cast-warning.cpp:47:5: warning: use of old-style cast [-Wold-style-cast]
> There are some open bug reports on similar subjects
> e.g. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7263#c8
From a quick read, it seems that the infrastructure to fix this
problem is in 4.8, but this particular problem isn't fixed?
Should I file another PR?
Thanks again,
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).