7

Consider the following example:

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 generates symbol named int f<int>() while GCC generates B::type f<int>() for the instantiation: https://godbolt.org/z/MCCza4

Why don't the compilers agree and shouldn't GCC also resolve B::type to int?

vitaut
  • 49,672
  • 25
  • 199
  • 336
  • Because the C++ standard does not require any specific symbol mangling convention on any C++ implementation. The exact details of how a C++ compiler mangles its symbols is entirely up to the compiler. – Sam Varshavchik Jul 07 '20 at 03:15
  • 1
    Sure, the standard doesn't guarantee any particular name mangling scheme (nor does it recognize that name mangling exists), but both GCC and Clang on x64 adhere to the Itanium ABI's name mangling scheme, which mandates exactly one mangling. – randomnetcat Jul 07 '20 at 03:18

1 Answers1

1

This is a known C++ CWG (Core Working Group) issue: 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.

vitaut
  • 49,672
  • 25
  • 199
  • 336