This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Request of new __attribute__ for switch statements (eliminationof the bounds check)
- From: Michael Matz <matz at suse dot de>
- To: Jamie Lokier <egcs at tantalophile dot demon dot co dot uk>
- Cc: Kevin Lawton <kevinlawton2001 at yahoo dot com>, <gcc at gcc dot gnu dot org>
- Date: Tue, 15 Oct 2002 22:27:07 +0200 (CEST)
- Subject: Re: Request of new __attribute__ for switch statements (eliminationof the bounds check)
Hi,
On Tue, 15 Oct 2002, Jamie Lokier wrote:
> > > (It would be appropriate to add a warning when an enum with this
> > > attribute is converted to an integer).
> >
> > That's not the problematic direction. I can't see why converting such an
> > enum to an integer would be dangerous. But converting _to_ such an enum
> > should get a warning.
>
> Good point. (I was thinking of enum arithmetic like `CAT | DOG' being
> disallowed for strict enums -- I believe that is defined for standard enums).
For the type system I would use the following argumentation (biased to C
not C++): First observe that strict enum are not an integer type (in
difference to normal ISO C enums), but can be implicitely converted to
one. Additionally strict enum shall not be arithmetic types (makes sense,
because we want to disallow arithmetics on this thing). Per 6.5.x (the
definitions of the different operators) all interesting operators operate
on arithmetic types. Ergo the only way to interpret 'BLA | BLUBB' is,
that both strict enums are (implicitely) converted to an integer type,
which makes the whole expression have integer type. That is you could
write: "unsigned int x = BLA | BLUBB;" without a warning, and I think
that's Ok. What you _can't_ do then is "enum E_strict e = BLA | BLUBB;"
because the RHS arithmetic expression can't be implicitely converted to an
E_strict. One would need an explicit cast, and that should get a warning.
Does that make sense?
Ciao,
Michael.