🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by David Callahan Fri, 15 Dec 1989 22:44
Nested type declarations--- question & bug report
#2098
Author: David Callahan
Date: Fri, 15 Dec 1989 22:44
106 lines
3491 bytes
In section 9.7 on Nested Class Declarations of the AT&T Product
Reference Manual for 2.0, it is stated that:

	The "exporting" of classes and typedefs and enumeration 
	names into an enclosing scope continues until the global 
	or a local block scope is reached.

Does that also include the names if individual constants in an 
enumeration type? 

This is directed to gnu.g++.bug because I have found what must be a
bug in g++ and I don't have acccess to cfront to compare.

Here is the example:

--------------------

struct Node {
      enum node_enum { other, load, store, add, test } ;
      node_enum value ;
    public:
      Node& operator=(node_enum e) { value = e ; return *this ; }
      int operator==(Node) ;
      Node operator=(int) ;
}  ;

struct Edge {
      enum edge_enum { load, store, add, test } ;
      edge_enum value ;
    public:
      Edge & operator=(edge_enum e) { value = e ; return *this ; }
}  ;


foo(Node & t) {

      node_enum n2 = Node::load ;
      t = Node::load ;
      t = 4 ;
      t = store ;                       // this is line 25
      t = Edge::load ;
}
-------------------- End Example ---------------

Running g++ 1.36.1 configured for sun3-nfp-os4, on this example I get
the following:

g++ -v -S enum.c
gcc version 1.36.1 (based on GCC 1.36)
 /usr/local/lib/g++-1.36.1/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -Dmc68020 enum.c /usr/tmp/cca09721.cpp
GNU CPP version 1.36
 /usr/local/lib/g++-1.36.1/gcc-cc1plus /usr/tmp/cca09721.cpp -quiet -dumpbase enum.c -version -o enum.s
GNU C++ version 1.36.1 (based on GCC 1.36) (68k, MIT syntax) compiled by GNU C version 1.36.
default target switches: -m68020 -mc68020 -mbitfield
enum.c: In function int foo (struct Node &):
enum.c:25: `store' undeclared (first use this function)
enum.c:25: (Each undeclared identifier is reported only once
enum.c:25: for each function it appears in.)

----------
g++ is making the individual names private to the class. This is
great, I wish the enumeration name was also private...

Looking at the assembler I observe that g++ also respects the
enumeration type when it does function resolution.

There does appear to be a bug implementing the store into t with
Edge::load. g++ appears to treat "Edge::load" as if were a
"node_enum" instead of implicitly casting it into and int. 
Here is the assembler for the above after the error on line 25
is commented out:

#NO_APP
gcc_compiled.:
.text
	.even
.globl _foo__FR4Node
_foo__FR4Node:
	link a6,#-4
	movel d2,sp@-
	moveq #1,d2
	movel d2,a6@(-4)
	movel a6@(8),a0
	moveq #1,d0
	movel d0,a0@
	movel a0,d1
	jra L6
L6:
	pea 4:w
	movel a6@(8),sp@-
	jbsr _op$assign_nop__4Nodei
	movel a6@(8),a0
	clrl d0
	addqw #8,sp
	movel d0,a0@
	movel a0,d1
	jra L7
L7:
L5:
	movel a6@(-8),d2
	unlk a6
	rts
---------------------------

David Callahan  				       david@tera.com
Tera Computer Co. 400 North 34th Street, Suite 300  Seattle WA, 98103
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