Skip to content

Commit

Permalink
Correct demangle working under clang on windows as well
Browse files Browse the repository at this point in the history
  • Loading branch information
zajo committed Aug 21, 2024
1 parent d3de93a commit bd9140c
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions include/boost/leaf/detail/demangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,24 @@ namespace leaf_detail
template <class Name>
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
}

Expand All @@ -64,7 +61,11 @@ inline std::ostream & print_type_str(std::basic_ostream<CharT, Traits> & os)
if( char const * t = type_str<Name>() )
{
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' )
Expand All @@ -83,10 +84,6 @@ inline std::ostream & print_type_str(std::basic_ostream<CharT, Traits> & 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) << ": ";
Expand Down

0 comments on commit bd9140c

Please sign in to comment.