Commit 2a40eb60 by Chris Mihelich Committed by Copybara-Service

Demangle C++20 constrained friend names, F (<source-name> | <operator-name>).

PiperOrigin-RevId: 641011959
Change-Id: I844d4eb99a9f9da160bb53e491dee753a70750df
parent 0cd50e6e
......@@ -823,8 +823,13 @@ static bool ParsePrefix(State *state) {
// ::= <local-source-name> [<abi-tags>]
// ::= <unnamed-type-name> [<abi-tags>]
// ::= DC <source-name>+ E # C++17 structured binding
// ::= F <source-name> # C++20 constrained friend
// ::= F <operator-name> # C++20 constrained friend
//
// <local-source-name> is a GCC extension; see below.
//
// For the F notation for constrained friends, see
// https://github.com/itanium-cxx-abi/cxx-abi/issues/24#issuecomment-1491130332.
static bool ParseUnqualifiedName(State *state) {
ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false;
......@@ -841,6 +846,15 @@ static bool ParseUnqualifiedName(State *state) {
return true;
}
state->parse_state = copy;
// F <source-name>
// F <operator-name>
if (ParseOneCharToken(state, 'F') && MaybeAppend(state, "friend ") &&
(ParseSourceName(state) || ParseOperatorName(state, nullptr))) {
return true;
}
state->parse_state = copy;
return false;
}
......
......@@ -160,6 +160,34 @@ TEST(Demangle, ConstrainedAutoInFunctionTemplate) {
EXPECT_STREQ(tmp, "f<>()");
}
TEST(Demangle, ConstrainedFriendFunctionTemplate) {
char tmp[100];
// Source:
//
// namespace ns {
// template <class T> struct Y {
// friend void y(Y) requires true {}
// };
// } // namespace ns
//
// y(ns::Y<int>{});
//
// LLVM demangling:
//
// ns::Y<int>::friend y(ns::Y<int>) requires true
ASSERT_TRUE(Demangle("_ZN2ns1YIiEF1yES1_QLb1E", tmp, sizeof(tmp)));
EXPECT_STREQ(tmp, "ns::Y<>::friend y()");
}
TEST(Demangle, ConstrainedFriendOperatorTemplate) {
char tmp[100];
// ns::Y<int>::friend operator*(ns::Y<int>) requires true
ASSERT_TRUE(Demangle("_ZN2ns1YIiEFdeES1_QLb1E", tmp, sizeof(tmp)));
EXPECT_STREQ(tmp, "ns::Y<>::friend operator*()");
}
TEST(Demangle, NonTemplateBuiltinType) {
char tmp[100];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment