From 8b6c3facb33ba247d5499393cdb4b5e0e8d5763e Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Mon, 28 Mar 2016 22:42:39 +0300 Subject: [PATCH] Fixes and GCC related improvements --- .../detail/compile_time_type_info.hpp | 141 ++++++++---------- 1 file changed, 63 insertions(+), 78 deletions(-) diff --git a/include/boost/type_index/detail/compile_time_type_info.hpp b/include/boost/type_index/detail/compile_time_type_info.hpp index 9827394..6e95827 100644 --- a/include/boost/type_index/detail/compile_time_type_info.hpp +++ b/include/boost/type_index/detail/compile_time_type_info.hpp @@ -67,7 +67,7 @@ #elif defined(__GNUC__) #ifndef BOOST_NO_CXX14_CONSTEXPR - // sizeof("static contexpr char boost::detail::ctti::s() [with long unsigned int Index = 82ul; T = ") - 1, sizeof("]") - 1 + // sizeof("static contexpr char boost::detail::ctti::s() [with long unsigned int Index = 0ul; T = ") - 1, sizeof("]") - 1 BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(91, 1, false, "") #else // sizeof("static const char* boost::detail::ctti::n() [with T = ") - 1, sizeof("]") - 1 @@ -92,6 +92,17 @@ namespace boost { namespace typeindex { namespace detail { ); } + template + BOOST_CXX14_CONSTEXPR inline void failed_to_get_function_name() BOOST_NOEXCEPT { + BOOST_STATIC_ASSERT_MSG( + sizeof(T) && false, + "TypeIndex library could not detect your compiler. " + "Please make the BOOST_TYPE_INDEX_FUNCTION_SIGNATURE macro use " + "correct compiler macro for getting the whole function name. " + "Define BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING to correct value after that." + ); + } + template BOOST_CXX14_CONSTEXPR inline const char* skip_begining_runtime(const char* begin, boost::mpl::false_) BOOST_NOEXCEPT { return begin; @@ -153,57 +164,49 @@ namespace boost { namespace typeindex { namespace detail { } #if !defined(__clang__) && defined(__GNUC__) && !defined(BOOST_NO_CXX14_CONSTEXPR) - // GCC - template + + template struct switch_{ typedef typename TDefault::type type; }; - - template - struct switch_<0, T0, T1, T2, T3, T4, TDefault>{ typedef typename T0::type type; }; - - template - struct switch_<1, T0, T1, T2, T3, T4, TDefault>{ typedef typename T1::type type; }; - - template - struct switch_<2, T0, T1, T2, T3, T4, TDefault>{ typedef typename T2::type type; }; - - template - struct switch_<3, T0, T1, T2, T3, T4, TDefault>{ typedef typename T3::type type; }; - - template - struct switch_<4, T0, T1, T2, T3, T4, TDefault>{ typedef typename T4::type type; }; +#define DEFINE_SWITCH(Index) \ + template \ + struct switch_{ typedef typename T##Index::type type; }; \ + /**/ - template + DEFINE_SWITCH(0) DEFINE_SWITCH(1) DEFINE_SWITCH(2) DEFINE_SWITCH(3) DEFINE_SWITCH(4) + DEFINE_SWITCH(5) DEFINE_SWITCH(6) DEFINE_SWITCH(7) DEFINE_SWITCH(8) +#undef DEFINE_SWITCH + + template struct index_seq {}; - template - struct append; - - template - struct append, Append...> { - typedef index_seq type; - }; - template> - struct make_index_seq { + struct make_index_seq; + + template + struct make_index_seq > { typedef typename switch_< - Size - Counter - 1, - make_index_seq::type >, - make_index_seq::type >, - make_index_seq::type >, - make_index_seq::type >, - make_index_seq::type >, - make_index_seq::type > + S - C - 1, + make_index_seq >, + make_index_seq >, + make_index_seq >, + make_index_seq >, + make_index_seq >, + make_index_seq >, + make_index_seq >, + make_index_seq >, + make_index_seq >, + make_index_seq > >::type type; }; - template - struct make_index_seq { - typedef T type; + template + struct make_index_seq > { + typedef index_seq type; }; - + template struct cstring { static constexpr std::size_t size_ = sizeof...(C) + 1; @@ -214,7 +217,6 @@ namespace boost { namespace typeindex { namespace detail { constexpr char cstring::data_[]; #endif - }}} // namespace boost::typeindex::detail namespace boost { namespace detail { @@ -237,27 +239,13 @@ struct ctti { + (Index >= 100000u ? 1u : 0u) + (Index >= 1000000u ? 1u : 0u) ; - + #if defined(BOOST_TYPE_INDEX_FUNCTION_SIGNATURE) return BOOST_TYPE_INDEX_FUNCTION_SIGNATURE[Index + offset]; #elif defined(__FUNCSIG__) return __FUNCSIG__[Index + offset]; - #elif defined(__PRETTY_FUNCTION__) \ - || defined(__GNUC__) \ - || (defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x5130)) \ - || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) \ - || (defined(__ICC) && (__ICC >= 600)) \ - || defined(__ghs__) \ - || defined(__DMC__) - return __PRETTY_FUNCTION__[Index + offset]; #else - BOOST_STATIC_ASSERT_MSG( - sizeof(T) && false, - "TypeIndex library could not detect your compiler. " - "Please make the BOOST_TYPE_INDEX_FUNCTION_SIGNATURE macro use " - "correct compiler macro for getting the whole function name. " - "Define BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING to correct value after that." - ); + return __PRETTY_FUNCTION__[Index + offset]; #endif } @@ -267,28 +255,30 @@ struct ctti { } template - constexpr static const char* n() - { - constexpr std::size_t size = sizeof( - #if defined(BOOST_TYPE_INDEX_FUNCTION_SIGNATURE) - BOOST_TYPE_INDEX_FUNCTION_SIGNATURE - #elif defined(__FUNCSIG__) - __FUNCSIG__ - #elif defined(__PRETTY_FUNCTION__) \ + constexpr static const char* n() { + #if defined(BOOST_TYPE_INDEX_FUNCTION_SIGNATURE) + constexpr std::size_t size = sizeof(BOOST_TYPE_INDEX_FUNCTION_SIGNATURE); + #elif defined(__FUNCSIG__) + constexpr std::size_t size = sizeof(__FUNCSIG__); + #elif defined(__PRETTY_FUNCTION__) \ || defined(__GNUC__) \ || (defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x5130)) \ || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) \ || (defined(__ICC) && (__ICC >= 600)) \ || defined(__ghs__) \ || defined(__DMC__) - __PRETTY_FUNCTION__ - #else - int - #endif - ); - + constexpr std::size_t size = sizeof(__PRETTY_FUNCTION__); + #else + boost::typeindex::detail::failed_to_get_function_name(); + #endif + + boost::typeindex::detail::assert_compile_time_legths< + (size > boost::typeindex::detail::ctti_skip_size_at_begin + boost::typeindex::detail::ctti_skip_size_at_end + sizeof("const *") - 1) + >(); + static_assert(!boost::typeindex::detail::ctti_skip_more_at_runtime, "Skipping for GCC in C++14 mode is unsupported"); + typedef typename boost::typeindex::detail::make_index_seq< - size - boost::typeindex::detail::ctti_skip_size_at_end - 7, + size - sizeof("const *") + 1, boost::typeindex::detail::ctti_skip_size_at_begin >::type idx_seq; return impl(idx_seq()); @@ -309,13 +299,8 @@ struct ctti { || defined(__DMC__) return boost::typeindex::detail::skip_begining< sizeof(__PRETTY_FUNCTION__) >(__PRETTY_FUNCTION__); #else - BOOST_STATIC_ASSERT_MSG( - sizeof(T) && false, - "TypeIndex library could not detect your compiler. " - "Please make the BOOST_TYPE_INDEX_FUNCTION_SIGNATURE macro use " - "correct compiler macro for getting the whole function name. " - "Define BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING to correct value after that." - ); + boost::typeindex::detail::failed_to_get_function_name(); + return ""; #endif } #endif