1 #ifndef BOOST_CORE_DEMANGLE_HPP_INCLUDED
2 #define BOOST_CORE_DEMANGLE_HPP_INCLUDED
6 // Copyright 2014 Peter Dimov
7 // Copyright 2014 Andrey Semashev
9 // Distributed under the Boost Software License, Version 1.0.
10 // See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt
13 #include <boost/config.hpp>
16 #if defined(BOOST_HAS_PRAGMA_ONCE)
20 // __has_include is currently supported by GCC and Clang. However GCC 4.9 may have issues and
21 // returns 1 for 'defined( __has_include )', while '__has_include' is actually not supported:
22 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63662
23 #if defined( __has_include ) && (!defined( BOOST_GCC ) || (__GNUC__ + 0) >= 5)
24 # if __has_include(<cxxabi.h>)
25 # define BOOST_CORE_HAS_CXXABI_H
27 #elif defined( __GLIBCXX__ ) || defined( __GLIBCPP__ )
28 # define BOOST_CORE_HAS_CXXABI_H
31 #if defined( BOOST_CORE_HAS_CXXABI_H )
33 // For some archtectures (mips, mips64, x86, x86_64) cxxabi.h in Android NDK is implemented by gabi++ library
34 // (https://android.googlesource.com/platform/ndk/+/master/sources/cxx-stl/gabi++/), which does not implement
35 // abi::__cxa_demangle(). We detect this implementation by checking the include guard here.
36 # if defined( __GABIXX_CXXABI_H__ )
37 # undef BOOST_CORE_HAS_CXXABI_H
50 inline char const * demangle_alloc( char const * name ) BOOST_NOEXCEPT;
51 inline void demangle_free( char const * name ) BOOST_NOEXCEPT;
53 class scoped_demangled_name
59 explicit scoped_demangled_name( char const * name ) BOOST_NOEXCEPT :
60 m_p( demangle_alloc( name ) )
64 ~scoped_demangled_name() BOOST_NOEXCEPT
69 char const * get() const BOOST_NOEXCEPT
74 BOOST_DELETED_FUNCTION(scoped_demangled_name( scoped_demangled_name const& ))
75 BOOST_DELETED_FUNCTION(scoped_demangled_name& operator= ( scoped_demangled_name const& ))
79 #if defined( BOOST_CORE_HAS_CXXABI_H )
81 inline char const * demangle_alloc( char const * name ) BOOST_NOEXCEPT
85 return abi::__cxa_demangle( name, NULL, &size, &status );
88 inline void demangle_free( char const * name ) BOOST_NOEXCEPT
90 std::free( const_cast< char* >( name ) );
93 inline std::string demangle( char const * name )
95 scoped_demangled_name demangled_name( name );
96 char const * const p = demangled_name.get();
109 inline char const * demangle_alloc( char const * name ) BOOST_NOEXCEPT
114 inline void demangle_free( char const * ) BOOST_NOEXCEPT
118 inline std::string demangle( char const * name )
129 #undef BOOST_CORE_HAS_CXXABI_H
131 #endif // #ifndef BOOST_CORE_DEMANGLE_HPP_INCLUDED