#153 Enum value cant refer to a previous val

closed-invalid
nobody
5
2001-10-01
2001-09-30
Michael Hope
No

See support/regression/tests/enum.c

Basically:

enum {
FIRST,
FIRST_ALIAS = FIRST
}

throws an 'Undefined symbol 'FIRST'' error.

Discussion

  • Kevin Vigor
    Kevin Vigor
    2001-10-01

    • status: open --> closed-invalid
     
  • Kevin Vigor
    Kevin Vigor
    2001-10-01

    Logged In: YES
    user_id=11484

    I don't believe this is a bug. To quote the ISO spec:

    6.7.2.2.2: The expression that defines the value of an
    enumerarion constant shall be an integer constant
    expression...

    6.7.2.2.4: ... The enumerated type is incomplete until after
    the } that terminates the list of enumerator declarations.

    An incomplete type is not a constant integer expression,
    thus I think the compiler is well within its rights to
    reject this code.

    My copy of Harbison & Steele notes:

    "The expression must be a constant expression of integral
    type, although some compilers may also allow expressions
    involving previously defined enumeration constants, as in

    enum boys { Bill = 10, John = Bill + 2 };"

    I guess gcc is one such compiler, because it accepts this
    code without comment even with -ansi -pedantic -Wall.

    So I conclude that this is not a bug. Counter-arguments
    gratefully accepted.