1

Here is a minimal example that does not have any includes:

template <bool B, typename T> struct enable_if { using type = T; };
template <typename T> struct enable_if<false, T> { };
template <bool B, typename T> using enable_if_t = typename enable_if<B, T>::type;

struct X {
    template <typename T, enable_if_t<sizeof(T) == 1, int> = 0>
    static void foo();
};

struct Y : X {
    using X::foo;

    template <typename T, enable_if_t<(sizeof(T) > 1), int> = 0>
    static void foo();
};

void test() {
    Y::foo<char>();
    Y::foo<int>();
}

gcc accepts this program (with the first call correctly invoking X::foo). clang rejects the call to Y::foo<char>(). Apparently, clang doesn't actually consider these functions to differ for some reason.

I swear I've run into this before, and I seem to recall there being some quirk in using-declarations and templates that makes this not as obvious as I might expect. Who's right?

Barry
  • 286,269
  • 29
  • 621
  • 977

0 Answers0