Commit 9605d816 by Chris Mihelich Committed by Copybara-Service

Demangle constrained auto types (Dk <type-constraint>).

PiperOrigin-RevId: 638831461
Change-Id: Ie30ff381e7d74a40a689b52e66b2e8bb81e0fda6
parent 9a2da1a4
......@@ -621,6 +621,7 @@ static bool ParseExprPrimary(State *state);
static bool ParseExprCastValueAndTrailingE(State *state);
static bool ParseQRequiresClauseExpr(State *state);
static bool ParseRequirement(State *state);
static bool ParseTypeConstraint(State *state);
static bool ParseLocalName(State *state);
static bool ParseLocalNameSuffix(State *state);
static bool ParseDiscriminator(State *state);
......@@ -1274,6 +1275,7 @@ static bool ParseDecltype(State *state) {
// ::= <substitution>
// ::= Dp <type> # pack expansion of (C++0x)
// ::= Dv <num-elems> _ # GNU vector extension
// ::= Dk <type-constraint> # constrained auto
//
static bool ParseType(State *state) {
ComplexityGuard guard(state);
......@@ -1346,6 +1348,11 @@ static bool ParseType(State *state) {
}
state->parse_state = copy;
if (ParseTwoCharToken(state, "Dk") && ParseTypeConstraint(state)) {
return true;
}
state->parse_state = copy;
// For this notation see CXXNameMangler::mangleType in Clang's source code.
// The relevant logic and its comment "not clear how to mangle this!" date
// from 2011, so it may be with us awhile.
......@@ -2292,8 +2299,6 @@ static bool ParseQRequiresClauseExpr(State *state) {
// <requirement> ::= T <type>
// <requirement> ::= Q <constraint-expression>
//
// <type-constraint> ::= <name>
//
// <constraint-expression> ::= <expression>
//
// https://github.com/itanium-cxx-abi/cxx-abi/issues/24
......@@ -2307,7 +2312,7 @@ static bool ParseRequirement(State *state) {
Optional(ParseOneCharToken(state, 'N')) &&
// This logic backtracks cleanly if we eat an R but a valid type doesn't
// follow it.
(!ParseOneCharToken(state, 'R') || ParseName(state))) {
(!ParseOneCharToken(state, 'R') || ParseTypeConstraint(state))) {
return true;
}
state->parse_state = copy;
......@@ -2321,6 +2326,11 @@ static bool ParseRequirement(State *state) {
return false;
}
// <type-constraint> ::= <name>
static bool ParseTypeConstraint(State *state) {
return ParseName(state);
}
// <local-name> ::= Z <(function) encoding> E <(entity) name> [<discriminator>]
// ::= Z <(function) encoding> E s [<discriminator>]
// ::= Z <(function) encoding> E d [<(parameter) number>] _ <name>
......
......@@ -150,6 +150,16 @@ TEST(Demangle, FunctionTemplateTemplateParamWithConstrainedArg) {
EXPECT_STREQ(tmp, "foo<>()");
}
TEST(Demangle, ConstrainedAutoInFunctionTemplate) {
char tmp[100];
// template <typename T> concept C = true;
// template <C auto N> void f() {}
// template void f<0>();
ASSERT_TRUE(Demangle("_Z1fITnDk1CLi0EEvv", tmp, sizeof(tmp)));
EXPECT_STREQ(tmp, "f<>()");
}
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