The following code works on gcc-4.1.2, but is rejected with gcc-4.2.0: class ABC0 { public: virtual ~ABC0() = 0; virtual int something() = 0; };
inline ABC0::~ABC0() { } struct C0; struct ABC1 : public ABC0 { explicit ABC1() : ABC0() { } virtual ABC0 *sometwhat() = 0; }; template<class X> struct C1 : public ABC1 { ABC0 *somewhat(); }; template<class X> ABC0 *C1<X>::somewhat() { return new C0; } struct C0 : public ABC0 { C0(int c) : ABC0() , _c(c) { } int something() { return 0; } private: int _c; }; $ g++ -V4.2.0 -c bug.cc bug.cc: In member function 'ABC0* C1<X>::somewhat()': bug.cc:34: error: invalid use of incomplete type 'struct C0' bug.cc:12: error: forward declaration of 'struct C0' -- Summary: template function cannot create object of forward declared class Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: thomas at maier-komor dot de GCC build triplet: i686-pc-cygwin GCC host triplet: i686-pc-cygwin GCC target triplet: i686-pc-cygwin http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31954