From 79251e26f356c503d7677685c76794000aaff849 Mon Sep 17 00:00:00 2001 From: Bhagirath Mehta Date: Thu, 11 Jun 2026 00:20:30 -0500 Subject: [PATCH] Rename demangle to mat_demangle to avoid boost name conflict typename.hpp defined both a global `demangle` function and a function-like macro `#define demangle(name) (name)`. The macro rewrites any `demangle` token in translation units that include this header -- including `boost::core::demangle` from boost/core/demangle.hpp -- producing a compile error when the SDK is integrated alongside boost. Rename the SDK helper (function + macro) to `mat_demangle` and update its sole external caller (print_backtrace in Utils.cpp). TYPENAME() is updated to match. No behavior change. Verified: a TU that includes typename.hpp and defines a namespaced `demangle` (as boost does) fails to compile with the old header and compiles cleanly after the rename (clang++ -std=c++17 -fsyntax-only). Files: lib/pal/typename.hpp, lib/utils/Utils.cpp Resolves #1048. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- lib/pal/typename.hpp | 6 +++--- lib/utils/Utils.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pal/typename.hpp b/lib/pal/typename.hpp index ce7f691de..22399998e 100644 --- a/lib/pal/typename.hpp +++ b/lib/pal/typename.hpp @@ -12,16 +12,16 @@ #include #include -__inline static std::string demangle(const char* name) { +__inline static std::string mat_demangle(const char* name) { int status = -4; std::unique_ptr res{ abi::__cxa_demangle(name, NULL, NULL, &status), std::free }; return (status == 0) ? res.get() : name; } -#define TYPENAME(t) demangle(typeid(t).name()).c_str() +#define TYPENAME(t) mat_demangle(typeid(t).name()).c_str() #define HAS_RTTI 1 #else -#define demangle(name) (name) +#define mat_demangle(name) (name) #if defined(_CPPRTTI) && defined(_WIN32) #define TYPENAME(t) typeid(t).name() diff --git a/lib/utils/Utils.cpp b/lib/utils/Utils.cpp index d1639088a..e2360ca18 100644 --- a/lib/utils/Utils.cpp +++ b/lib/utils/Utils.cpp @@ -58,7 +58,7 @@ namespace MAT_NS_BEGIN { strings = backtrace_symbols(array, size); printf("XXXXXXXXXXXXXXXXXXXX Obtained %zd stack frames:\n", size); for (i = 0; i < size; i++) - printf("[%2lu] %s\n", i, demangle(strings[i]).c_str()); + printf("[%2lu] %s\n", i, mat_demangle(strings[i]).c_str()); printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); free(strings); #endif