This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Bug in template parameter type deduction


This bug report might be related to another one posted by me a couple of weeks
ago; however, I've decided to send it for the sake of completeness. The gcc
version in test was 2.95.2.

#line 1 "prob12.cc"
#include <iostream>

template <class Object, class Property>
class provided : public Object {
public:
   const char* who() const { return "const"; }
   const char* who() { return "non-const"; }
};

template <class Property, class Object> inline
provided<Object,Property>&
provide(Object& x)
{
   return reinterpret_cast<provided<Object,Property>&>(x);
}

template <class Property, class Object> inline
const provided<Object,Property>&
provide(const Object& x)
{
   return reinterpret_cast<const provided<Object,Property>&>(x);
}

class property { };

class object { public: object() { } };

int main()
{
   object x1;
   const object x2;
   cout << "x1: " << provide<property>(x1).who() << endl
	<< "x2: " << provide<property>(x2).who() << endl;
   return 0;
}


prob12.cc: In function `int main()':
prob12.cc:33: call of overloaded `provide (const object &)' is ambiguous
prob12.cc:13: candidates are: class provided<const object,property> & provide<property, const object>(const object &)
prob12.cc:20:                 const class provided<object,property> & provide<property, object>(const object &)


The error disappears if either the Property parameter is removed overall, so
that all remaining template parameters are to be deduced, or both parameters of 
`provide' are explicitly specified at the point of instantiation, i.e.
 ... provide<property,object>(x1) ...

That is, this mixed mode where a subset of template parameters is specified
and the rest is to be deduced seems to make trouble to the poor compiler.

With best regards,
Ewgenij Gawrilow
Dept. of Mathematics, Technical University of Berlin

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]