Commit ffa1e4a5 by Chris Mihelich Committed by Copybara-Service

Demangle new-expressions with braced-init-lists.

PiperOrigin-RevId: 640908672
Change-Id: I85bed6e7d79b24b693007c08acde8e28e3e1429c
parent e7a5d7ac
......@@ -2291,6 +2291,11 @@ static bool ParseExpression(State *state) {
}
// <initializer> ::= pi <expression>* E
// ::= il <braced-expression>* E
//
// The il ... E form is not in the ABI spec but is seen in practice for
// braced-init-lists in new-expressions, which are standard syntax from C++11
// on.
static bool ParseInitializer(State *state) {
ComplexityGuard guard(state);
if (guard.IsTooComplex()) return false;
......@@ -2301,6 +2306,13 @@ static bool ParseInitializer(State *state) {
return true;
}
state->parse_state = copy;
if (ParseTwoCharToken(state, "il") &&
ZeroOrMore(ParseBracedExpression, state) &&
ParseOneCharToken(state, 'E')) {
return true;
}
state->parse_state = copy;
return false;
}
......
......@@ -1148,6 +1148,36 @@ TEST(Demangle, GlobalScopeNewExpression) {
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, NewExpressionWithEmptyBraces) {
char tmp[80];
// Source:
//
// template <class T> decltype(T{*new T{}}) f() { return T{}; }
// template decltype(int{*new int{}}) f<int>();
//
// GNU demangling:
//
// decltype (int{*(new int{})}) f<int>()
EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_denw_S0_ilEEEv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, NewExpressionWithNonemptyBraces) {
char tmp[80];
// Source:
//
// template <class T> decltype(T{*new T{42}}) f() { return T{}; }
// template decltype(int{*new int{42}}) f<int>();
//
// GNU demangling:
//
// decltype (int{*(new int{42})}) f<int>()
EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_denw_S0_ilLi42EEEEv", tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, SimpleArrayNewExpression) {
char tmp[80];
......@@ -1212,6 +1242,22 @@ TEST(Demangle, GlobalScopeArrayNewExpression) {
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, ArrayNewExpressionWithTwoElementsInBraces) {
char tmp[80];
// Source:
//
// template <class T> decltype(T{*new T[2]{1, 2}}) f() { return T{}; }
// template decltype(int{*new int[2]{1, 2}}) f<int>();
//
// GNU demangling:
//
// decltype (int{*(new int{1, 2})}) f<int>()
EXPECT_TRUE(Demangle("_Z1fIiEDTtlT_dena_S0_ilLi1ELi2EEEEv",
tmp, sizeof(tmp)));
EXPECT_STREQ("f<>()", tmp);
}
TEST(Demangle, ReferenceQualifiedFunctionTypes) {
char tmp[80];
......
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