为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?

Why do gcc and clang generate different symbol names for an instantiation of a function template?

考虑以下示例:

struct A {
  using type = int;
};

template <typename T>
using B = A;

template <typename T>
typename B<T>::type f() { return {}; }

template B<int>::type f<int>();

Clang 生成名为 int f<int>() 的符号,而 GCC 为实例化生成 B::type f<int>()https://godbolt.org/z/MCCza4

为什么编译器不同意 GCC 也不应该将 B::type 解析为 int

这是一个已知的 C++ CWG(核心工作组)问题:https://wg21.cmeerw.net/cwg/issue2037, quoting Richard Smith

On the one hand, the alias template can introduce SFINAE conditions, so it should be instantiation-dependent and mangled. On the other hand, the language rules permit this template to be redeclared using the result of expanding the alias template, so mangling it can't be correct.