-Wold-style-cast
Stephan T. Lavavej
stl@caltech.edu
Thu Sep 4 12:22:00 GMT 2003
-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
More information about the Gcc
mailing list