Article View: gnu.g++.bug
Article #1596error in g++ handling of enum's in classes and structs
From: "Douglas C. Schmidt"
Date: Tue, 03 Jan 1989 04:41
Date: Tue, 03 Jan 1989 04:41
41 lines
1557 bytes
1557 bytes
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
Technical Details
Message-ID:
<8901022042.aa12119@PARIS.ICS.UCI.EDU>Path:
arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%crimee.ics.uci.eduShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%crimee.ics.uci.edu
From: schmidt%crimee.ics.uci.edu@PARIS.ICS.UCI.EDU ("Douglas C. Schmidt")
Newsgroups: gnu.g++.bug
Subject: error in g++ handling of enum's in classes and structs
Message-ID: <8901022042.aa12119@PARIS.ICS.UCI.EDU>
Date: 3 Jan 89 04:41:39 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 41