aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/debugging/internal/demangle.cc13
-rw-r--r--absl/debugging/internal/demangle_test.cc70
2 files changed, 83 insertions, 0 deletions
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc
index 40a55c7d..f04e4dbc 100644
--- a/absl/debugging/internal/demangle.cc
+++ b/absl/debugging/internal/demangle.cc
@@ -1877,6 +1877,10 @@ static bool ParseBracedExpression(State *state) {
// ::= cv <type> <expression> # type (expression)
// ::= cv <type> _ <expression>* E # type (expr-list)
// ::= tl <type> <braced-expression>* E
+// ::= dc <type> <expression>
+// ::= sc <type> <expression>
+// ::= cc <type> <expression>
+// ::= rc <type> <expression>
// ::= st <type>
// ::= <template-param>
// ::= <function-param>
@@ -1942,6 +1946,15 @@ static bool ParseExpression(State *state) {
}
state->parse_state = copy;
+ // dynamic_cast, static_cast, const_cast, reinterpret_cast.
+ //
+ // <expression> ::= (dc | sc | cc | rc) <type> <expression>
+ if (ParseCharClass(state, "dscr") && ParseOneCharToken(state, 'c') &&
+ ParseType(state) && ParseExpression(state)) {
+ return true;
+ }
+ state->parse_state = copy;
+
// Parse the conversion expressions jointly to avoid re-parsing the <type> in
// their common prefix. Parsed as:
// <expression> ::= cv <type> <conversion-args>
diff --git a/absl/debugging/internal/demangle_test.cc b/absl/debugging/internal/demangle_test.cc
index 96051d31..2c582415 100644
--- a/absl/debugging/internal/demangle_test.cc
+++ b/absl/debugging/internal/demangle_test.cc
@@ -706,6 +706,76 @@ TEST(Demangle, ReferenceQualifiedFunctionTypes) {
EXPECT_STREQ("f()", tmp);
}
+TEST(Demangle, DynamicCast) {
+ char tmp[80];
+
+ // Source:
+ //
+ // template <class T> auto f(T* p) -> decltype(dynamic_cast<const T*>(p)) {
+ // return p;
+ // }
+ // struct S {};
+ // void g(S* p) { f(p); }
+ //
+ // Full LLVM demangling of the instantiation of f:
+ //
+ // decltype(dynamic_cast<S const*>(fp)) f<S>(S*)
+ EXPECT_TRUE(Demangle("_Z1fI1SEDTdcPKT_fp_EPS1_", tmp, sizeof(tmp)));
+ EXPECT_STREQ("f<>()", tmp);
+}
+
+TEST(Demangle, StaticCast) {
+ char tmp[80];
+
+ // Source:
+ //
+ // template <class T> auto f(T* p) -> decltype(static_cast<const T*>(p)) {
+ // return p;
+ // }
+ // void g(int* p) { f(p); }
+ //
+ // Full LLVM demangling of the instantiation of f:
+ //
+ // decltype(static_cast<int const*>(fp)) f<int>(int*)
+ EXPECT_TRUE(Demangle("_Z1fIiEDTscPKT_fp_EPS0_", tmp, sizeof(tmp)));
+ EXPECT_STREQ("f<>()", tmp);
+}
+
+TEST(Demangle, ConstCast) {
+ char tmp[80];
+
+ // Source:
+ //
+ // template <class T> auto f(T* p) -> decltype(const_cast<const T*>(p)) {
+ // return p;
+ // }
+ // void g(int* p) { f(p); }
+ //
+ // Full LLVM demangling of the instantiation of f:
+ //
+ // decltype(const_cast<int const*>(fp)) f<int>(int*)
+ EXPECT_TRUE(Demangle("_Z1fIiEDTccPKT_fp_EPS0_", tmp, sizeof(tmp)));
+ EXPECT_STREQ("f<>()", tmp);
+}
+
+TEST(Demangle, ReinterpretCast) {
+ char tmp[80];
+
+ // Source:
+ //
+ // template <class T> auto f(T* p)
+ // -> decltype(reinterpret_cast<const T*>(p)) {
+ // return p;
+ // }
+ // void g(int* p) { f(p); }
+ //
+ // Full LLVM demangling of the instantiation of f:
+ //
+ // decltype(reinterpret_cast<int const*>(fp)) f<int>(int*)
+ EXPECT_TRUE(Demangle("_Z1fIiEDTrcPKT_fp_EPS0_", tmp, sizeof(tmp)));
+ EXPECT_STREQ("f<>()", tmp);
+}
+
TEST(Demangle, ThreadLocalWrappers) {
char tmp[80];