This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34996] New: Base class of explicitly instantiated class doesn't get instantiated
- From: "rbuergel at web dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Jan 2008 13:13:08 -0000
- Subject: [Bug c++/34996] New: Base class of explicitly instantiated class doesn't get instantiated
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
test.h:
struct Base
{
virtual int getX() const=0;
};
template <typename ThisType> class Derived1: public Base
{
protected:
static const int X;
public:
virtual int getX() const{ return X; }
};
template<int id> class Derived2 : public Derived1<Derived2<id> > {};
test.cpp:
#include "test.h"
template<typename U> const int Derived1<U>::X = 0;
template class Derived2<1>;
// template class Derived1<Base, Derived2::StaticImpl<1> >; //that shouldn't be
necessary
main.cpp:
#include "test.h"
int main()
{
Base& r = *new Derived2< 1 >();
};
g++ main.cpp test.cpp
/tmp/ccyQeFe1.o: In function `Derived1<Derived2<1> >::getX() const':
main.cpp:(.text._ZNK8Derived1I8Derived2ILi1EEE4getXEv[Derived1<Derived2<1>
>::getX() const]+0x4): undefined reference to `Derived1<Derived2<1> >::X'
collect2: ld returned 1 exit status
gcc doesn't to instantiate "Derived1<Base, Derived2::StaticImpl<1> >" - the
Base class of the explicitly instantiated "Derived2<1>"
some curiosities:
1. outlining getX() into test.cpp makes it work
2. using g++ test.cpp main.cpp (just reversing the order of the files on the
cmd line) works(!), but compiling each file individually and then linking it
breaks.
I can recognise this behaviour with 3.4.6, 4.1.2, 4.2.2 and 4.3 (snapshot from
20080125)
--
Summary: Base class of explicitly instantiated class doesn't get
instantiated
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rbuergel at web dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34996