Thread View: gnu.g++.bug
1 messages
1 total messages
Started by "Douglas C. Schmidt"
Tue, 03 Jan 1989 04:41
error in g++ handling of enum's in classes and structs
Author: "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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads