Ambiguity regarding class-scope using-declarations that name member function templates

20 views
Skip to first unread message

Brian Bi

unread,
Aug 8, 2017, 3:53:31 PM8/8/17
to std-dis...@isocpp.org
This question is based on an SO post.

Consider the following code [coliru link]:

#include <type_traits>
struct B {
    template <int n> void f();
};
struct D : B {
    using B::f;
    template <class T> void f();
};

int main()
{
    D d;
    d.f<0>();
    d.f<int>();
}


GCC accepts it, while Clang rejects it. It seems evident that GCC considers the two function templates to overload with each other in D, while Clang considers B::f to be hidden in D.

Now the standard says:
When a using-declarator brings declarations from a base class into a derived class, member functions and member function templates in the derived class override and/or hide member functions and member function templates with the same name, parameter-type-list, cv-qualification, and ref-qualifier (if any) in a base class (rather than conflicting).
Such hidden or overridden declarations are excluded from the set of declarations introduced by the using-declarator.
It doesn't say that the template parameter lists also have to match---so it seems that Clang is correct according to the letter of the law. However, I am wondering whether GCC is following the spirit. I find it hard to imagine that the code above was intended not to compile, since the two function templates are allowed to overload with each other if declared in the same scope. Is there a defect in the wording?

--
Brian Bi
Reply all
Reply to author
Forward
0 new messages