GCC 2.95.2 bug, Deeply Nested Virtuals

Andy Glew glew@cs.wisc.edu
Wed Jan 19 21:29:00 GMT 2000


The following shell session demonstrates a bug
in GCC 2.95 (also found in GCC 2.95.2 using GNU ld)
related to defining virtual methods in a deeply
nested context.

Please do not be distracted by whether or not I explicitly
define ~inner_base(){} --- I have demonstrated the bug both ways.


egeus ~/hack/deeply-nested-virtuals 9 : cat test.cc
#include <iostream.h>

class outer {
   public:
      class inner_base {
	 public:
	    virtual void apply() = 0;
	    virtual ~inner_base() {};
      };
      void method() {
	 class inner_derived : public inner_base {
	    public:
	       void apply() {
		  cout << "inner_derived inside outer::method()" << endl;
	       }
	 };
	 inner_derived id;
	 id.apply();
      }
};

int 
main()
{
   outer obj;
   obj.method();
}
egeus ~/hack/deeply-nested-virtuals 10 : make test
g++     test.cc   -o test
egeus ~/hack/deeply-nested-virtuals 11 : ./test
inner_derived inside outer::method()
egeus ~/hack/deeply-nested-virtuals 12 : g++ -O test.cc   -o test
Undefined			first referenced
 symbol  			    in file
_._Q35outer16method__5outer.0_13inner_derived.427 /var/tmp/ccnPOIo5.o
apply__Q35outer16method__5outer.0_13inner_derived.426 /var/tmp/ccnPOIo5.o
ld: fatal: Symbol referencing errors. No output written to test
collect2: ld returned 1 exit status
egeus ~/hack/deeply-nested-virtuals 13 : cat test2.cc
#include <iostream.h>

class outer {
   public:
      class inner_base {
	 public:
	    virtual void apply() = 0;
	    virtual ~inner_base() {};
      };
      class inner_derived : public inner_base {
	 public:
	    void apply() {
	       cout << "inner_derived inside outer outside method()" << endl;
	    }
      };
      void method() {
	 inner_derived id;
	 id.apply();
      }
};

int 
main()
{
   outer obj;
   obj.method();
}
egeus ~/hack/deeply-nested-virtuals 14 : g++ -O test2.cc   -o test2
egeus ~/hack/deeply-nested-virtuals 15 : ./test2
inner_derived inside outer outside method()
egeus ~/hack/deeply-nested-virtuals 16 : g++ test2.cc   -o test2
egeus ~/hack/deeply-nested-virtuals 17 : ./test2
inner_derived inside outer outside method()
egeus ~/hack/deeply-nested-virtuals 18 : g++ -v
Reading specs from /s/gcc-2.95/sunx86_56/lib/gcc-lib/i386-pc-solaris2.6/2.95/specs
gcc version 2.95 19990728 (release)
egeus ~/hack/deeply-nested-virtuals 20 : ld -V
ld: Software Generation Utilities - Solaris/ELF (3.0)
egeus ~/hack/deeply-nested-virtuals 21 : uname -a
SunOS egeus 5.6 Generic_105182-17 i86pc i386
egeus ~/hack/deeply-nested-virtuals 22 : 

---

Andy Glew, glew@cs.wisc.edu

[Place URGENT in email subject line for mail filter prioritization.]


More information about the Gcc-bugs mailing list