itanium-cxx-abi / cxx-abi

C++ ABI Summary
508 stars 96 forks source link

Compilers disagree on mangling of implicit `(*this).` #118

Open cpplearner opened 3 years ago

cpplearner commented 3 years ago
struct A {
  template<class U> int f();
  template<class T> auto g() -> decltype(f<T>());
};

struct B {
  A a;
  template<class T> auto g() -> decltype(a.f<T>());
};

int main() {
  A a;
  B b;

  a.g<int>();
// gcc  :  call _ZN1A1gIiEEDTcldtdefpT1fIT_EEEv
// clang:  call _ZN1A1gIiEEDTcl1fIT_EEEv
// icc  :  call _ZN1A1gIiEEDTcl1fIT_EEEv

  b.g<int>();
// gcc  :  call _ZN1B1gIiEEDTcldtdtdefpT1a1fIT_EEEv
// clang:  call _ZN1B1gIiEEDTcldtdtdefpT1a1fIT_EEEv
// icc  :  call _ZN1B1gIiEEDTcldt1a1fIT_EEEv
}

It seems that GCC always includes the implicit (*this). in the mangling, Clang includes (*this). only in some cases (when the member name is non-dependent?), and ICC never does.

Which behavior should be specified?

rjmccall commented 3 years ago

I think the current rule ("expression manglings reflect a prefix traversal of the syntactic expression tree") strongly suggests that implicit *this should never be mangled. And that seems to have been the consensus when this was previously discussed on cxx-abi-dev. I guess compilers just never did this consistently.

@jicama, @zygoloid, what do the implementations think about changing this mangling at this point?

jicama commented 3 years ago

This seems like a bug in GCC (tracked at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98756).

I'd want to fix this in the compiler after we resolve issue #38. The general rule is to mangle the syntactic form, but #38 demonstrates that we need to make an exception for name lookup, since the same name can mean different things in different contexts.