With clang, template methods in derived class hide parent's methods with same name, even if disabled by SFINAE and even with using-declaration

128 views Asked by At

Please, have a look at this small sample code

#include <type_traits>

struct base {
    template <typename T>
    int func(T);
};

struct derived: base {
    using base::func;

    template <typename T, std::enable_if_t<std::is_same_v<T,const char*>>* = nullptr>
    int func(T);
};    

auto x = derived().func(1);

It compiles fine with gcc and icc, it doesn't with clang, which complains like this:

<source>:17:20: error: no matching member function for call to 'func'

auto x = derived().func(1);
         ~~~~~~~~~~^~~~

<source>:13:9: note: candidate template ignored: requirement 'std::is_same_v<int, const char *>' was not satisfied [with T = int]

    int func(T);
        ^

As if no using-declaration were added to struct derived. If I weren't using templates, I'd for sure know that this would be clang's problem. However, I am not sure the fact I'm using templates and SFINAE implies different rules got to be used, so here's my question: which compiler is right? Clang, or gcc and icc?

Here's a working example of the issue on godbolt: https://godbolt.org/z/xv98SP

0

There are 0 answers