This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC 3.0.2: errno conflict.


[ this discussion was on gcc, I'm adding libstdc++ ]

Maxim Dementiev writes:

> Excuse me if this bug is wellknown for peaple.
> This code copile with error by g++ 3.0.2 on Linux 2.2.19 (i386).
> (See commented line below.)
> If rename "errno" to "errno1" - all works fine.
> Is it a bug?

[ testcase uses errno as an identifier, and there is a collision with
the errno macro in glibc, but the only #include was for <iostream> ]

I think that the conclusion is that, since you did not include <errno.h>
or <cerrno> explicitly, there is a bug.  errno is allowed to be a macro,
but only if you ask for one of these headers, which you did not.
(Nevertheless some user of your class may want to use the system errno in
the same file as the class you define, so you may want to avoid the use of
the errno identifier anyway).

I think that the problem is in libstdc++, in locale_facets.tcc.
locale_facets.tcc's do_get templates clear and then test errno.
So this is a libstdc++ bug.

It seems that an easy fix would be to remember if errno is defined
as a macro or not at the beginning of the header, then test again
at the end.  If it becomes defined, undefine it.  Something like

... at the beginning of locale_facets.tcc:

#ifndef errno
#define __errno_was_not_defined
#endif

... at the end of locale_facets.tcc:

#if defined(errno) && defined(__errno_was_not_defined)
#undef errno
#undef __errno_was_not_defined
#endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]