This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
problem with g++ & -O optimization
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: problem with g++ & -O optimization
- From: Ian Nixon <ian at tharas dot com>
- Date: Thu, 08 Jul 1999 17:00:46 -0700
Hi folks,
I see the following problem when using:
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
on sparc-sun-solaris2.6
With the following code:
#include <stdio.h>
struct Base {
virtual void action () = 0;
void DoIt () {
action ();
}
};
void func ()
{
struct Derived : public Base {
void action () { printf ("Hello Mum\n"); }
};
Derived d;
d.DoIt ();
}
main ()
{
func ();
}
// --- End Code
this is OK:
g++ main.cc -o main
but this is not:
g++ main.cc -o main -O
Undefined first referenced
symbol in file
action__Q210func__Fv.0_7Derived.4 /var/tmp/ccv0pGG1.o
ld: fatal: Symbol referencing errors. No output written to main
collect2: ld returned 1 exit status
Has anyone seen this before? Moving the "Derived" struct out of the
function makes the problem go away.
Thanks
Ian.