This is the mail archive of the gcc-bugs@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]

Re: Enum is a class?


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


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