Tuesday, 17 September 2013

using and overloading a template member function of a base class?

using and overloading a template member function of a base class?

In the following, struct Y overloads X's member function f. Both overloads
are template functions, but take different arguments (typename and int),
to be explicitly specified:
struct X
{
template <typename> static bool f() { return true; }
};
struct Y : public X
{
using X::f;
template <int> static bool f() { return false; }
};
int main()
{
std::cout << Y::f <void>() << " " << Y::f <0>() << std::endl;
}
This prints 1 0 using gcc, as expected. However, clang (3.3) complains that
[...] error: no matching function for call to 'f'
std::cout << Y::f <void>() << " " << Y::f <0>() << std::endl;
^~~~~~~~~~~
[...] note: candidate template ignored: invalid explicitly-specified argument
for 1st template parameter
template <int> static bool f() { return false; }
^
i.e., can only see Y's version. I've tried
using X::template f;
instead, with no success. The same happens for non-static (template)
member functions. So is this a bug?

No comments:

Post a Comment