Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 293825 - sys-libs/glibc: old-style cast in __FD_SET macro breaks strict C++ compilation
Summary: sys-libs/glibc: old-style cast in __FD_SET macro breaks strict C++ compilation
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: High minor (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-20 10:36 UTC by Erik
Modified: 2010-06-08 04:18 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erik 2009-11-20 10:36:21 UTC
sys-libs/glibc-2.9_p20081201-r2 provides the files /usr/include/{bit,sy}s/select.h. Application programs are supposed to use some macros defined there; FD_CLR, FD_ISSET and FD_SET. Those macros are just wrappers around corresponding macros __FD_SET, __FD_CLR and __FD_ISSET.

They can be used also from C++-programs, but it breaks when strict C++ compilation is enabled; -Werror=old-style-cast. Every experienced C++ programmer knows that old-style casts should never be used in C++ code (it is explained in Bjarne Stroustrup's book from 2000). Therefore C++ programmers want to build their programs with -Werror=old-style-cast to make sure that no old-style cast crept in somehow. But this fails with some included macros from C libraries. This is the case with the mentioned macros.

This is not the first time that such issues are found. So far it has worked well to fix them. For example SDL has the following definitions:
#ifdef __cplusplus
#define SDL_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
#define SDL_static_cast(type, expression) static_cast<type>(expression)
#else
#define SDL_reinterpret_cast(type, expression) ((type)(expression))
#define SDL_static_cast(type, expression) ((type)(expression))
#endif

Those macros are used for every cast in the SDL include files. (But it is of course not needed in the SDL implementation files.)

(See [http://www.libsdl.org/cgi/viewvc.cgi?view=revision&revision=4431], [http://www.libsdl.org/cgi/viewvc.cgi?view=revision&revision=4432], [http://www.libsdl.org/cgi/viewvc.cgi?view=revision&revision=4973].)

Some boost code has also been ported to C++ recently for this reason (but they just changed it to C++ casts because their code was no longer C-compatible anyway, see [https://svn.boost.org/trac/boost/changeset/53665/]).

Reproducible: Always

Steps to Reproduce:
1. Use one of the macros, for example FD_SET, in a C++ program.
2. Try to compile it with g++ -Werror=old-style-cast.
Actual Results:  
error: use of old-style cast

Expected Results:  
(successful compilation)
Comment 1 Erik 2009-11-20 10:58:04 UTC
Same problem in /usr/include/netinet/in.h (IN_CLASSA, IN_CLASSB, IN_CLASSC, IN_CLASSD, IN_EXPERIMENTAL, IN_BADCLASS, INADDR_ANY, INADDR_BROADCAST, INADDR_NONE, INADDR_LOOPBACK, INADDR_UNSPEC_GROUP, INADDR_ALLHOSTS_GROUP, INADDR_ALLRTRS_GROUP, INADDR_MAX_LOCAL_GROUP, IN6_IS_ADDR_UNSPECIFIED, IN6_IS_ADDR_LOOPBACK, IN6_IS_ADDR_MULTICAST, IN6_IS_ADDR_LINKLOCAL, IN6_IS_ADDR_SITELOCAL, IN6_IS_ADDR_V4MAPPED, IN6_ARE_ADDR_EQUAL, IN6_IS_ADDR_MC_NODELOCAL, IN6_IS_ADDR_MC_LINKLOCAL, IN6_IS_ADDR_MC_SITELOCAL, IN6_IS_ADDR_MC_ORGLOCAL and IN6_IS_ADDR_MC_GLOBAL)
Comment 2 Erik 2009-11-20 11:22:40 UTC
Same problem in /usr/include/sys/mman.h (MAP_FAILED).
Comment 3 SpanKY gentoo-dev 2010-06-08 04:18:05 UTC
the casts have always been this way and from what i can see, will always be this way.  we're not going to diverge in Gentoo on this.

you can file a bug about this with the glibc people as i dont think this is a issue that really needs to be "fixed" ...
http://sources.redhat.com/bugzilla/