template parameters deduction bug
Ewgenij Gawrilow
gawrilow@math.TU-Berlin.DE
Thu Nov 19 09:56:00 GMT 1998
egcs-1.1.1 prerelase refuses to translate the following code:
-------------------------------------------------------------
template <class Base, class Elem>
class GenericSet { };
template <class Elem>
class Set : public GenericSet< Set<Elem>, Elem> {
public:
Set() { }
#if VARIANT != 1
template <class Base2>
explicit Set(const GenericSet<Base2,Elem>& s2);
#endif
};
template <class Elem, class Base1, class Base2>
void g (const GenericSet<Base1,Elem>& s1, const GenericSet<Base2,Elem>& s2) { }
template <class Elem>
struct cmp {
#if VARIANT != 2
template <class Base1, class Base2>
void f (const GenericSet<Base1,Elem>& s1, const GenericSet<Base2,Elem>& s2) const { }
#else
template <class Base1>
void f (const GenericSet<Base1,Elem>& s1, const Set<Elem>& s2) const { }
#endif
};
void test()
{
Set<int> s1, s2;
cmp<int> c;
g(s1,s2);
c.f(s1,s2); // <*********** HERE
}
-------------------------------------------------------------
complaining about:
% /usr/local/egcs/bin/g++ -c test.cc -DVARIANT=0 -Wall -v
Reading specs from /usr/local/egcs/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.58/specs
gcc version egcs-2.91.58 19981101 (egcs-1.1.1 pre-release)
/usr/local/egcs/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.58/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -Wall -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) -DVARIANT=0 test.cc /tmp/cc2KUjEj.ii
GNU CPP version egcs-2.91.58 19981101 (egcs-1.1.1 pre-release) (sparc)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/egcs/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.58/include/g++
/usr/local/include
/usr/local/egcs/sparc-sun-solaris2.6/include
/usr/local/egcs/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.58/include
/usr/include
End of search list.
/usr/local/egcs/lib/gcc-lib/sparc-sun-solaris2.6/egcs-2.91.58/cc1plus /tmp/cc2KUjEj.ii -quiet -dumpbase test.cc -Wall -version -o /tmp/cc1H8FNj.s
GNU C++ version egcs-2.91.58 19981101 (egcs-1.1.1 pre-release) (sparc-sun-solaris2.6) compiled by GNU C version egcs-2.91.58 19981101 (egcs-1.1.1 pre-release).
test.cc: In function `void test()':
test.cc:34: no matching function for call to `cmp<int>::f (Set<int> &, Set<int> &)'
The error disappears when either the second constructor is removed
(-DVARIANT=1) or there is only one parameter that should be deduced under consideration
of the class hierarchy (-DVARIANT=2).
Curiously, that this bug shows only with template member functions: the
call to the function `g' one line above is resolved correctly despite of two
parameters to be deduced.
With best regards,
Ewgenij Gawrilow
Dept. of Mathematics
Technical University of Berlin
More information about the Gcc-bugs
mailing list