[demangler] Don't allow the template parameters from the <encoding> in a
<local-name> to leak out into later parts of the name.
This caused us to fail to demangle certain constructs involving generic
lambdas.
GitOrigin-RevId: 553dbb6d7b32cc786281dea2c58a420bcbc9bb82
diff --git a/src/demangle/ItaniumDemangle.h b/src/demangle/ItaniumDemangle.h
index dcece38..0f81675 100644
--- a/src/demangle/ItaniumDemangle.h
+++ b/src/demangle/ItaniumDemangle.h
@@ -5096,6 +5096,8 @@
// ::= <special-name>
template <typename Derived, typename Alloc>
Node *AbstractManglingParser<Derived, Alloc>::parseEncoding() {
+ ScopedTemplateParamList EncodingTemplateParams(this);
+
if (look() == 'G' || look() == 'T')
return getDerived().parseSpecialName();
diff --git a/test/test_demangle.pass.cpp b/test/test_demangle.pass.cpp
index c75b697..b8b2ad5 100644
--- a/test/test_demangle.pass.cpp
+++ b/test/test_demangle.pass.cpp
@@ -29792,6 +29792,16 @@
// "auto inline_func()::'lambda'<int, int>(int, int) const"
{"_ZZ11inline_funcvENKUlTyTyT_T0_E_clIiiEEDaS_S0_", "auto inline_func()::'lambda'<typename $T, typename $T0>($T, $T0)::operator()<int, int>($T, $T0) const"},
{"_ZZ11inline_funcvENKUlTyTyT_T1_T0_E_clIiiiEEDaS_S0_S1_", "auto inline_func()::'lambda'<typename $T, typename $T0>($T, auto, $T0)::operator()<int, int, int>($T, auto, $T0) const"},
+ {"_ZN1XIZ1fIiEvOT_EUlOT_DpT0_E_EclIJEEEvDpT_", "void X<void f<int>(int&&)::'lambda'(auto&&, auto...)>::operator()<>()"},
+ // FIXME: This is wrong, should demangle to the same as the previous entry.
+ // See https://github.com/itanium-cxx-abi/cxx-abi/issues/106.
+ {"_ZN1XIZ1fIiEvOT_EUlS2_DpT0_E_EclIJEEEvDpT_", "void X<void f<int>(int&&)::'lambda'(int&&, auto...)>::operator()<>()"},
+
+ // FIXME: This is wrong; the S2_ backref should expand to OT_ and then to
+ // "double&&". But we can't cope with a substitution that represents a
+ // different type the node it is a substitute for.
+ // See https://github.com/itanium-cxx-abi/cxx-abi/issues/106.
+ {"_Z1h1XIJZ1fIiEDaOT_E1AZ1gIdEDaS2_E1BEE", "h(X<auto f<int>(int&&)::A, auto g<double>(int&&)::B>)"},
{"_Z1fIL4Enumn1EEvv", "void f<(Enum)-1>()"},