------- Comment #27 from simon_baldwin at yahoo dot com  2006-05-02 21:01 
-------
Here's a relatively simple test case, in case anyone wants one, that reproduces
either this problem, or a very similar one.  It requires a mix of compilers,
and of optimization selections, to reproduce, though.  One gcc 3 compiler and
one gcc 4 one should do it.


$ cat foo.h
class Foo {
 public:
  virtual ~Foo() {}
  virtual inline int f(int x) {
    switch (x) {
      case 0: return 0; break;
      case 1: return 1; break;
      case 2: return 2; break;    // cases 0 to 2 bulk out the switch statement

      case 3: return 999; break;  // cases 3 and 4 can be coalesced
      case 4: return 999; break;
    }
    return -1;
  }
};

extern int g(int);
extern int h();

$ cat lib1.cc
#include "foo.h"

int g(int i) {
  Foo f;
  return f.f(i);
}

$ cat lib2.cc
#include "foo.h"

int h() {
  Foo f;
  return f.f(0) + g(0);
}

$ cat main.cc
#include "foo.h"

int main() {
  return g(0) + h();
}

$ ./g++-3.4.5 -Wall -W -pedantic -O2 -c lib1.cc
$ ./g++-3.4.5 -Wall -W -pedantic -O0 -c lib2.cc
$ ./g++-4.1.0 -Wall -W -pedantic -o main lib1.o lib2.o main.cc
/path/to/i686-unknown-linux-gnu/bin/ld: `.gnu.linkonce.t._ZN3Foo1fEi'
referenced in section `.rodata' of lib2.o: defined in discarded section
`.gnu.linkonce.t._ZN3Foo1fEi' of lib2.o
... and so on

In this case, the ld in gcc 4.1 is version 2.16.1.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16625

Reply via email to