public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/26173]  New: derived template class with virtual functions implemented in a seperated file does not link
@ 2006-02-08 11:21 alexander dot schmitt at wibu dot com
  2006-02-08 12:48 ` [Bug c++/26173] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: alexander dot schmitt at wibu dot com @ 2006-02-08 11:21 UTC (permalink / raw)
  To: gcc-bugs

The following case can be reproduced with the attached sample.

If I have a C++ base class with a virtual function and a derived (template)
class and the virtual function is implemented in a own file (-> classb.cpp),
the linker does not find the symbol of the function.

If the function is implemented inline it will works.

The problem seems to be that the object file (classb.o) does not contains the
symbol information.

The problem seems to be new with gcc 4.0. With gcc 3.3 it works.

We have reproduced this with gcc 4.0.1 on Mac OS X and Linux.

Using the sample:
- unpack attached test.zip
- call ./ma.sh in shell terminal (gcc 4.0 envirnment must be set)

For me that seems to be a bug because I have not found a compiler switch, etc.
to make this working.

==================
-> proj.h
#include <stdio.h>
#include <unistd.h>

class A {
public:
  A() {
    ma = 0;
  } // A()
  virtual ~A() {
  } // A()

  virtual int Method1() = 0;

protected:
  int ma;
}; // A


template <typename T> class B {
public:
  B() {
    mb = 0;
  } // B()
  virtual ~B() {
  } // B()

  virtual int Method1();

protected:
  T mb;
}; // B

==================
-> main.cpp
#include "proj.h"

int main()
{
  B<short> bs;
  bs.Method1();
  B<int> bi;
  bi.Method1();
  B<long> bl;
  bl.Method1();
  return 0;
} // main()

==================
-> classb.cpp
#include "proj.h"

template class B<short>;
template class B<int>;
template class B<long>;

template <typename T> int B<T>::Method1()
{
  printf("pid = %ld\n", (long) getpid());
  return 0;
} // Method1()

==================
-> ma.sh (for Mac OS X)
g++ -c -O1 -arch ppc -arch i386 -o main.o main.cpp
g++ -c -O1 -arch ppc -arch i386 -o classb.o classb.cpp
g++ -o Test1ppc -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk main.o
classb.o -framework Carbon -lstdc++
g++ -o Test1i386 -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk main.o
classb.o -framework Carbon -lstdc++


-- 
           Summary: derived template class with virtual functions
                    implemented in a seperated file does not link
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexander dot schmitt at wibu dot com


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/26173] derived template class with virtual functions implemented in a seperated file does not link
  2006-02-08 11:21 [Bug c++/26173] New: derived template class with virtual functions implemented in a seperated file does not link alexander dot schmitt at wibu dot com
@ 2006-02-08 12:48 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-08 12:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-08 12:48 -------
template class B<short>;
template class B<int>;
template class B<long>;

template <typename T> int B<T>::Method1()
{...}
--------
This is your issue.  Move the instantiations below the defintion of the method
definition.
This is a dup of bug 24511 which describes why this is behavior is correct and
why the bug is also still open though.

*** This bug has been marked as a duplicate of 24511 ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-02-08 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-08 11:21 [Bug c++/26173] New: derived template class with virtual functions implemented in a seperated file does not link alexander dot schmitt at wibu dot com
2006-02-08 12:48 ` [Bug c++/26173] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).