This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

problem with g++ & -O optimization



  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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]