11

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?

bolov
  • 72,283
  • 15
  • 145
  • 224
HCSF
  • 2,387
  • 1
  • 14
  • 40

0 Answers0