This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
-Wold-style-cast
- From: "Stephan T. Lavavej" <stl at caltech dot edu>
- To: <gcc at gcc dot gnu dot org>
- Date: Thu, 4 Sep 2003 03:53:21 -0700
- Subject: -Wold-style-cast
- Reply-to: <stl at caltech dot edu>
-Wold-style-cast is emitting warnings when it probably shouldn't.
Consider winsock2.h from MinGW:
[...idempotency guards...]
#if __GNUC__ >=3
#pragma GCC system_header
#endif
[...hideous Windows garbage...]
#define INVALID_SOCKET (SOCKET)(~0)
[...more of the same...]
Suppose meow.cc includes winsock2.h and mentions INVALID_SOCKET. Everywhere
else, meow.cc uses modern casts. If meow.cc is compiled with
-Wold-style-cast (to insure that no C casts creep into the code) every use
of INVALID_SOCKET triggers a warning.
There is no simple way around this. Not using -Wold-style-cast admits
defeat, hacking the header is hardly a good idea, and defining something new
in meow.cc (call it MEOW_INVALID_SOCKET) that just happens to be equal to
INVALID_SOCKET and then using that is weaselly and prone to breakage if
INVALID_SOCKET ever changes. I happen to have chosen the last method, but
still, -Wold-style-cast could be improved.
I don't know if gcc can be made to not warn about C casts in macros which
are defined in a gcc system header, but it sure would be nice. Of course, C
casts which don't appear in a macro but do appear at the point of use should
probably be warned about. For example:
// In a system header
#define SOMETHING char
#define MEOW char)
// In user code
(SOMETHING) 5; // Should probably be warned about
(unsigned MEOW 5; // Should probably be warned about
Stephan T. Lavavej
http://stl.caltech.edu