This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Enum is a class?
- To: "Leonid A. Broukhis" <leob at best dot com>
- Subject: Re: Enum is a class?
- From: "Alastair J. Houghton" <ajh8 at doc dot ic dot ac dot uk>
- Date: Sat, 06 Feb 1999 14:28:20 +0000
- CC: EGCS-bugs <egcs-bugs at cygnus dot com>
- Organization: Imperial College of Science, Medicine and Technology, London
- References: <199902052233.OAA25454@shell7.ba.best.com>
Leonid A. Broukhis wrote:
>
> To recapitulate the subject:
>
> enum x {
> x1, x2, x3
> };
>
> struct elem_t {
> x a :10;
> x b :10;
> };
>
> template <class T> bool operator!= (const T& x, const T & y)
> {
> return !(x == y);
> }
>
> bool f(elem_t z) {
>
> // replace a with b and watch the error disappear
> // Explicit cast of z.a to x also helps!!!
>
> return ( x1 != z.a);
> }
>
> >OK. I just checked in the EGCS source. Your problem is
> >caused by a piece of code written by Jason Merrill
> >(jason@cygnus.com). It appears that the C++ standard
> >does specify that enums are subject to operator
> >overloading, though they aren't full class types.
> >The change, for your interest, was made in '94, so
> >any EGCS version later than that will not compile
> >your code.
>
> Right; and the bug went unnoticed until STL came.
Is it a bug? I'm still not certain. I think it may just
be another of those great "features" of C++.
> In any case, the fact that an explicit casting helps demonstrates
> that something is wrong inside EGCS. The template requires the
> two operands to be of the same type. The first one, x1, is of type x;
> if the second one, from egcs' point of view, is of the same type
> for all purposes, then the casting should not have helped; if it
> is of a different type (e.g. x:10),
> then an implicit cast operation must be performed.
Explicit casting will force the compiler to generate a
temporary variable to hold a full "x". A reference to this
can be generated. However you just can't have a reference
to a bitfield, although the bitfield's type is "x". Maybe
the compiler should be "fixed" to understand this special
situation so that it compiles your program. I'm not sure;
I'll ask Jason what he thinks.
____________________________________________________________
Alastair Houghton ajh8@ic.ac.uk
(ISE 3) Imperial College, London