From bd9140c2f7fea5f869d2f7862eb5a40686d4e25b Mon Sep 17 00:00:00 2001 From: Emil Dotchevski Date: Tue, 20 Aug 2024 22:53:15 -0700 Subject: [PATCH] Correct demangle working under clang on windows as well --- include/boost/leaf/detail/demangle.hpp | 39 ++++++++++++-------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/include/boost/leaf/detail/demangle.hpp b/include/boost/leaf/detail/demangle.hpp index 8d9a349f..f1ded0c0 100644 --- a/include/boost/leaf/detail/demangle.hpp +++ b/include/boost/leaf/detail/demangle.hpp @@ -34,27 +34,24 @@ namespace leaf_detail template inline char const * type_str() { -#if defined(_MSC_VER) +#if defined(__clang__) + BOOST_LEAF_ASSERT(leaf_detail::check_prefix(__PRETTY_FUNCTION__, "const char *boost::leaf::type_str() [Name = ") == 44); + return __PRETTY_FUNCTION__ + 44; +#elif defined(__GNUC__) + BOOST_LEAF_ASSERT(leaf_detail::check_prefix(__PRETTY_FUNCTION__, "const char* boost::leaf::type_str() [with Name = ") == 49); + return __PRETTY_FUNCTION__ + 49; +#elif defined _MSC_VER if( char const * p = std::strstr(__FUNCSIG__, "boost::leaf::type_str<") ) return p + 22; else return __FUNCSIG__; #else -# if defined(__clang__) - BOOST_LEAF_ASSERT(leaf_detail::check_prefix(__PRETTY_FUNCTION__, "const char *boost::leaf::type_str() [Name = ") == 44); - return __PRETTY_FUNCTION__ + 44; -# elif defined(__GNUC__) - BOOST_LEAF_ASSERT(leaf_detail::check_prefix(__PRETTY_FUNCTION__, "const char* boost::leaf::type_str() [with Name = ") == 49); - return __PRETTY_FUNCTION__ + 49; -# else - if( int clang_style = leaf_detail::check_prefix(__PRETTY_FUNCTION__, "const char *boost::leaf::type_str() [Name = ") ) - return __PRETTY_FUNCTION__ + clang_style; - else if( int gcc_style = leaf_detail::check_prefix(__PRETTY_FUNCTION__, "const char* boost::leaf::type_str() [with Name = ") ) - return __PRETTY_FUNCTION__ + gcc_style; - else - return __PRETTY_FUNCTION__; - return nullptr; -# endif + if( int clang_style = leaf_detail::check_prefix(__PRETTY_FUNCTION__, "const char *boost::leaf::type_str() [Name = ") ) + return __PRETTY_FUNCTION__ + clang_style; + else if( int gcc_style = leaf_detail::check_prefix(__PRETTY_FUNCTION__, "const char* boost::leaf::type_str() [with Name = ") ) + return __PRETTY_FUNCTION__ + gcc_style; + else + return __PRETTY_FUNCTION__; #endif } @@ -64,7 +61,11 @@ inline std::ostream & print_type_str(std::basic_ostream & os) if( char const * t = type_str() ) { char const * end = std::strchr(t, 0); -#ifdef _MSC_VER +#if defined(__clang__) || defined(__GNUC__) + BOOST_LEAF_ASSERT(end != t); + BOOST_LEAF_ASSERT(end[-1] == ']'); + return os.write(t, end - t - 1) << ": "; +#elif defined(_MSC_VER) BOOST_LEAF_ASSERT(end - t > 7); BOOST_LEAF_ASSERT(std::memcmp(end - 7, ">(void)", 7) == 0); if( *t == 's' ) @@ -83,10 +84,6 @@ inline std::ostream & print_type_str(std::basic_ostream & os) t += 5; } return os.write(t, end - t - 7) << ": "; -#elif defined(__clang__) || defined(__GNUC__) - BOOST_LEAF_ASSERT(end != t); - BOOST_LEAF_ASSERT(end[-1] == ']'); - return os.write(t, end - t - 1) << ": "; #else if( end != t && end[-1] == ']') return os.write(t, end - t - 1) << ": ";