This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
wrong template parameter deduction
- To: gcc-bugs at gcc dot gnu dot org
- Subject: wrong template parameter deduction
- From: Ewgenij Gawrilow <gawrilow at math dot TU-Berlin dot DE>
- Date: Wed, 1 Mar 2000 17:09:53 +0100 (MET)
The following piece of code can't be compiled by gcc 2.95.2.
#line 1 "prob.cc"
template <class C>
struct A {
typedef typename C::obj obj;
typedef typename C::cobj cobj;
static obj g(C& c) { return c.g(); }
static cobj g(const C& c) { return c.g(); }
};
#if defined(WORK_AROUND)
template <class C>
struct A<const C> {
typedef typename C::cobj obj;
};
#endif
template <class C> inline
A<C>::obj g(C& c)
{
return A<C>::g(c);
}
template <class C> inline
A<C>::cobj g(const C& c)
{
return A<C>::g(c);
}
class cont {
public:
class obj { };
class cobj { };
obj g();
cobj g() const;
};
void f(const cont& c)
{
g(c);
}
prob.cc: In instantiation of `A<const cont>':
prob.cc:19: instantiated from here
prob.cc:7: `A<const cont>::g(const cont &)' has already been declared in `A<const cont>'
It seems as if the template parameter deduction is being made twice, once when
analyzing the return value of g(c) within f(), and then during the
instantiation of the body of ::g. It wasn't that bad, hadn't the first attempt
lead to wrong results.
Compiled with -DWORK_AROUND, everything gets fine but looks pretty ugly.
The compiler and system configuration are:
% uname -a
SunOS sokol 5.7 Generic_106541-08 sun4u sparc SUNW,UltraSPARC-IIi-Engine
% g++ -v
Using builtin specs.
gcc version 2.95.2 19991024 (release)
% cat tmp/gcc-build/config.status
#!/bin/sh
# This file was generated automatically by configure. Do not edit.
# This directory was configured as follows:
.../tmp/gcc-2.95.2/configure --with-gcc-version-trigger=.../tmp/gcc-2.95.2/gcc/version.c --host=sparc-sun-solaris2.6 --enable-shared --enable-version-specific-runtime-libs --enable-languages=c++ --with-gxx-include-dir=/usr/local/include/C++ --norecursion
# using "mh-frag" and "mt-frag"
With best regards,
Ewgenij Gawrilow
Dept. of Mathematics, Technical University of Berlin