This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Template Method Specialization Trouble in G++ 3.0
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Template Method Specialization Trouble in G++ 3.0
- From: Jim Peterson <jspeter at jimsara dot org>
- Date: Wed, 01 Aug 2001 21:40:25 EDT
- Reply-To: jspeter at jimsara dot org
To whom it may concern:
I've appended a bug report below for g++ version 3.0. Please, let me
know
how to fix or work around this problem (avoiding 'abstract method' errors
via a template parameter).
Thank you for your time,
--Jim
==============================================================================
Typing g++ -v -o t.o t.cc -save-temps produces the messages given below:
==============================================================================
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.0/specs
Configured with: ../gcc-3.0/configure --prefix=/usr
Thread model: single
gcc version 3.0
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.0/cpp0 -lang-c++ -D__GNUG__=3
-D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -v -D__GNUC__=3
-D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux
-D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix
-D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386
-Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ t.cc t.ii
GNU CPP version 3.0 (cpplib) (i386 Linux/ELF)
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/g++-v3
/usr/include/g++-v3/i686-pc-linux-gnu
/usr/include/g++-v3/backward
/usr/include
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.0/include
/usr/i686-pc-linux-gnu/include
End of search list.
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.0/cc1plus -fpreprocessed t.ii -quiet
-dumpbase t.cc -version -o t.s
GNU CPP version 3.0 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0 (i686-pc-linux-gnu)
compiled by GNU C version 3.0.
t.cc:42: no `T* B<T, true>::newT()' member function declared in class `B<T,
true>'
t.cc:42: template definition of non-template `T* B<T, true>::newT()'
t.cc:45: no `T* B<T, false>::newT()' member function declared in class
`B<T,
false>'
t.cc:45: template definition of non-template `T* B<T, false>::newT()'
t.cc: In member function `T* A<T, ClassIsAbstract>::newT() [with T = C,
bool
ClassIsAbstract = true]':
t.cc:52: instantiated from here
t.cc:26: cannot allocate an object of type `C'
t.cc:26: because the following virtual functions are abstract:
t.cc:30: virtual char* C::msg()
==============================================================================
/*
I used to have code like class A, below, but g++ v. 3.0 will no longer
compile it because of the abstract method in C (even though the
definition
of A<C,true>::newT() will never try to instantiate an object of type C).
To try to get around this issue, I attempted to modify to class B, but
compiling reports:
t.cc:42: no `T* B<T, true>::newT()' member function declared in class `B<T,
true>'
t.cc:42: template definition of non-template `T* B<T, true>::newT()'
t.cc:45: no `T* B<T, false>::newT()' member function declared in class
`B<T,
false>'
t.cc:45: template definition of non-template `T* B<T, false>::newT()'
Is it accurate to report that no such member function is declared? I'm
under the impression that this code should work.
*/
template<class T,bool ClassIsAbstract>
class A
{
public:
T* newT()
{
if(ClassIsAbstract) return 0;
else return new T();
}
};
class C { public: virtual char* msg() = 0; };
A<C,true> a;
template<class T,bool ClassIsAbstract>
class B
{
public:
T* newT();
};
template<class T>
T* B<T,true>::newT() { return 0; }
template<class T>
T* B<T,false>::newT() { return new T(); }
B<C,true> b;
int main()
{
a.newT();
return 0;
}