schmidt%crimee.ics.uci.edu@PARIS.ICS.UCI.EDU ("Douglas C. Schmidt") (01/03/89)
Hi, G++ 1.32 incorrectly handles the scope of enumerated types declared in struct's and classes. Here's an example: ---------------------------------------- int FOO = 10; struct foo { enum bar { FOO, BAR }; }; main ( ) { int i = FOO; printf ( "i = %d\n", i); // this should print out 10 } ---------------------------------------- g++ doesn't compile the code above, complaining that: ---------------------------------------- foo.c:4: `FOO' redeclared as different kind of symbol foo.c:1: previous declaration of `FOO' foo.c:4: warning: `FOO' was declared `extern' and later `static' ---------------------------------------- However, according to Lippman and Moo: ``In C++, enumerations are local to the class [ or struct ] in which they are declared.'' ( page 131, 1988 USENIX C++ Conference Proceedings ). Therefore, the only correct way to reference enum bar's FOO is via the visibility operator, i.e.: int i = foo::FOO // sets i to 0, in this case. g++ seems to be erroneously using the C visibility rules in this case. Doug