Index: lib/AST/ItaniumMangle.cpp =================================================================== --- lib/AST/ItaniumMangle.cpp +++ lib/AST/ItaniumMangle.cpp @@ -2532,6 +2532,15 @@ // ::= dt // ::= pt if (base) { + + // Ignore member expressions involving anonymous unions. + while (const auto *ME = dyn_cast(base)) { + if (ME->getMemberDecl()->getIdentifier()) + break; + base = ME->getBase(); + isArrow = ME->isArrow(); + } + if (base->isImplicitCXXThis()) { // Note: GCC mangles member expressions to the implicit 'this' as // *this., whereas we represent them as this->. The Itanium C++ ABI Index: test/CodeGenCXX/mangle-exprs.cpp =================================================================== --- test/CodeGenCXX/mangle-exprs.cpp +++ test/CodeGenCXX/mangle-exprs.cpp @@ -217,3 +217,41 @@ template void a(decltype(noexcept(int()))); // CHECK: void @_ZN5test51aIiEEvDTnxcvT__EE( } + +namespace test6 { + template + struct X { + + union { + union { + int m; + }; + }; + + template + auto implicit_this(F f) const -> decltype(f(m)) {} + + template + auto explicit_this_arrow(F f) const -> decltype(f(this->m)) {} + + template + auto explicit_this_dot(F f) const -> decltype(f((*this).m)) {} + }; + + struct Y { void operator()(int); }; + + void instantiate() { + X x; + Y y; + + // CHECK: call void @_ZNK5test61XIiE13implicit_thisINS_1YEEEDTclfp_dtdefpT1mEET_( + x.implicit_this(y); + + // CHECK: call void @_ZNK5test61XIiE19explicit_this_arrowINS_1YEEEDTclfp_ptfpT1mEET_( + x.explicit_this_arrow(y); + + // CHECK: call void @_ZNK5test61XIiE17explicit_this_dotINS_1YEEEDTclfp_dtdefpT1mEET_( + x.explicit_this_dot(y); + } +} +