template function matching with specialization

Viewed 72

I tried the following code with GCC 10.0 and Clang 10.0:

template <template <typename> typename>
struct Foo {
    Foo() { std::cout << "generic" << std::endl; }
};

template <typename>
struct Bar {};

template <typename T>
using Fake_Bar = Bar<T>;

template <>
struct Foo<Bar> {
    Foo() { std::cout << "specialization" << std::endl; }
};

int main() {
    Foo<Bar> a;
    Foo<Fake_Bar> b;
}

And they gave different outputs:

GCC:

specialization
specialization

Clang:

specialization
generic

Which one is correct per C++17 standard? And what's the rule?

0 Answers
Related