(gcc 2.95 NT4 SP6) function declaration with enum argument

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Sun Mar 5 04:22:00 GMT 2000


> Do you mean that
> 
> enum TLanguage;
> 
> is invalid? I don't think so.

He means exactly that. There is no point in arguing against the
language definition.

> > an extension, try with -pedantic.
> 
> I don't see why an extension should be needed for my code to compile. It
> seems just straight C++ to me.

Well, it may seem straight C++ to you, but it certainly is not
standard C++. 7.2 ([dcl.enum]) defines enumerations as

enum­name:
         identifier

enum­specifier:
         enum identifier-opt { enumerator­list-opt }

enumerator­list:
         enumerator­definition
         enumerator­list , enumerator­definition

enumerator­definition:
         enumerator
         enumerator = constant­expression

enumerator:
         identifier

so there is no option to leave out the curly brackets.

You could think that 'enum foo' should be an elaborated-type-specifier
(it is), but 3.4.4, [basic.lookup.elab]/2 says

# If the elaborated­type­specifier refers to an enum­name and this
# lookup does not find a previously declared enum­name, the
# elaborated­type­specifier is ill­formed.

So you can use 'enum foo;' only if you had foo declared previously.

If you question this line of reasoning, please discuss it in one of
the public C++ fora first, eg. comp.lang.c++.moderated, or
comp.std.c++.

Regards,
Martin


More information about the Gcc-bugs mailing list