Topic: Is enum-name a simple-type-name? (was Borland Bug ?)


Author: jamshid@ses.com (Jamshid Afshar)
Date: Sat, 13 Nov 1993 00:05:04 GMT
Raw View
In article <jean-claude.bourut.13.000EFF0C@gsi.fr>,
JClaude Bourut <jean-claude.bourut@gsi.fr> wrote:
>The following program compiles under Borland C++. I think it's a bug

Btw, Cfront 3.0.2 and gcc also allow the code.

>class foo {
>public:
>    enum Bar {foofoo, foobar, barbar } ;
>};
>
>void main(){
>    if ( !foo::Bar()) {}
>}

It doesn't seem to be legal, but for consistency's sake it probably
should.  I don't think the fact that Bar is nested affects the
legality of the code (though it does oddly make the resulting
expression look like a member function call).  I don't think the `!'
affects the legality either.  So, here's a simplified example:

 enum Bar { bar };
 main() {
    if (Bar()) {}  // legal?
 }

ARM 5.2.3 Explicit Type Conversion says "A simple-type-name (7.1.6)
followed by a (empty) pair of parentheses constructs a value for the
specified type."  A simple-type-name is:

 complete-class-name
 qualified-type-name
 char
 short
 ....

This means:

 if (int()) {   // okay
    /*...*/
 }

is legal although the result of "int()" is an undefined int value.

The problem is that a simple-type-name seems to exclude enum-names
(like Bar).  A qualified-type-name can be a typedef-name or a
class-name::qualified-type-name.  This means that:

 enum Bar { bar };
 typedef Bar TD;
 main() {
    if (Bar()) {}  // apparently illegal
    if (TD()) {}   // legal!
 }

I don't think this behavior is intentional, but the June Working
Papers seem to read the same way as the ARM.  Either I'm misreading
the grammar or ANSI/ISO should fix it to allow an enum-name to be a
simple-type-name.  Comments?

Jamshid Afshar
jamshid@ses.com