This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ bug
- To: gcc-bugs at gcc dot gnu dot org
- Subject: g++ bug
- From: Martin Gerbershagen <ger at ulm dot temic-semi dot de>
- Date: Mon, 8 May 2000 17:35:20 +0200 (METDST)
Hi,
I found the following bug in the g++ compiler. It occurs in all
compiler version up to 2.95.2 on several platforms (sun,hp,linux). The
bug is caused by the optimizer whem local classes with virtual
functions are used. It seems, that the optimizer optimizes some
symbols away, that are referenced in the virtual tables.
This is the isolated example code to demonstrate the problem:
------ file a.h ----
class A {
public:
virtual int Foo() const = 0;
A(){}
virtual ~A();
};
------- file a.C ----
#include "a.h"
A::~A(){}
------ file bug3.C ---
#include "a.h"
int main(int, char**)
{
class B : public A {
public:
int Foo() const { return 0; }
B(){}
~B(){}
};
B b;
return 0;
}
-------------------
Class A provides a virtual function Foo, that is implemented in the
local class B within function main(). The program can be compiles
correctly, but cannot be linked, when compiled with -O. In this case I
get the followin link errors:
bug3.o(.gnu.linkonce.d.__vt_Q26main.0_1B+0x8): undefined reference to `Foo__CQ26main.0_1B.6'
bug3.o(.gnu.linkonce.d.__vt_Q26main.0_1B+0xc): undefined reference to `_._Q26main.0_1B.8'
collect2: ld returned 1 exit status
The link error only occurs, if the code is compiled in two different
modules, but not, if if is contained in one single module.
The compilation commands are:
g++ -c -O a.C
g++ -c -O bug3.C
g++ a.o bug3.o
I hope, the examples code is small enough, to find the bug easily.
Best regards
--
**********************************************************************
* Martin Gerbershagen Tel: +49 731 5094 206 *
* TEMIC Semiconductor Fax: +49 731 5094 288 *
* Lise Meitner Str. 15 mailto:martin.gerbershagen@ulm.temic-semi.de *
* D-89081 Ulm *
**********************************************************************