diff options
-rw-r--r-- | absl/debugging/internal/demangle.cc | 9 | ||||
-rw-r--r-- | absl/debugging/internal/demangle_test.cc | 33 |
2 files changed, 42 insertions, 0 deletions
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index 381a2b50..3ef21581 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc @@ -1461,6 +1461,9 @@ static bool ParseTemplateArgs(State *state) { // ::= <expr-primary> // ::= J <template-arg>* E # argument pack // ::= X <expression> E +// ::= Tk <type> <type> # constraint +// +// TODO(b/323420445): Support templated constraints. static bool ParseTemplateArg(State *state) { ComplexityGuard guard(state); if (guard.IsTooComplex()) return false; @@ -1560,6 +1563,12 @@ static bool ParseTemplateArg(State *state) { return true; } state->parse_state = copy; + + if (ParseTwoCharToken(state, "Tk") && ParseType(state) && ParseType(state)) { + return true; + } + state->parse_state = copy; + return false; } diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc index a16ab75e..c1b61253 100644 --- a/absl/debugging/internal/demangle_test.cc +++ b/absl/debugging/internal/demangle_test.cc @@ -31,6 +31,39 @@ namespace { using ::testing::ContainsRegex; +TEST(Demangle, FunctionTemplate) { + char tmp[100]; + + // template <typename T> + // int foo(T); + // + // foo<int>(5); + ASSERT_TRUE(Demangle("_Z3fooIiEiT_", tmp, sizeof(tmp))); + EXPECT_STREQ(tmp, "foo<>()"); +} + +TEST(Demangle, FunctionTemplateWithNesting) { + char tmp[100]; + + // template <typename T> + // int foo(T); + // + // foo<Wrapper<int>>({ .value = 5 }); + ASSERT_TRUE(Demangle("_Z3fooI7WrapperIiEEiT_", tmp, sizeof(tmp))); + EXPECT_STREQ(tmp, "foo<>()"); +} + +TEST(Demangle, FunctionTemplateWithConstraint) { + char tmp[100]; + + // template <std::integral T> + // int foo(T); + // + // foo<Wrapper<int>(5); + ASSERT_TRUE(Demangle("_Z3fooITkSt8integraliEiT_", tmp, sizeof(tmp))); + EXPECT_STREQ(tmp, "foo<>()"); +} + // Test corner cases of boundary conditions. TEST(Demangle, CornerCases) { char tmp[10]; |