diff --git a/include/boost/type_traits/common_type.hpp b/include/boost/type_traits/common_type.hpp index 03f9bd9..194c7c4 100644 --- a/include/boost/type_traits/common_type.hpp +++ b/include/boost/type_traits/common_type.hpp @@ -42,6 +42,9 @@ #include #endif +#include +#include + //----------------------------------------------------------------------------// // // // C++03 implementation of // @@ -53,6 +56,14 @@ namespace boost { + namespace type_traits_detail { + + template + struct std_decay: boost::remove_cv< + typename boost::decay::type> {}; + + } + // prototype #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template @@ -78,7 +89,7 @@ namespace boost { { BOOST_STATIC_ASSERT_MSG(sizeof(T) > 0, "The template arguments to common_type must be complete types"); public: - typedef T type; + typedef typename type_traits_detail::std_decay::type type; }; // 2 args @@ -93,13 +104,13 @@ namespace type_traits_detail { #if !defined(BOOST_NO_CXX11_DECLTYPE) public: - typedef decltype(declval() ? declval() : declval()) type; + typedef typename std_decay() ? declval() : declval())>::type type; #elif defined(BOOST_COMMON_TYPE_USE_TYPEOF) static typename add_rvalue_reference::type declval_T(); // workaround gcc bug; not required by std static typename add_rvalue_reference::type declval_U(); // workaround gcc bug; not required by std static typename add_rvalue_reference::type declval_b(); public: - typedef __typeof__(declval_b() ? declval_T() : declval_U()) type; + typedef typename std_decay<__typeof__(declval_b() ? declval_T() : declval_U())>::type type; #elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) public: typedef typename detail_type_traits_common_type::common_type_impl< @@ -111,7 +122,7 @@ namespace type_traits_detail { static typename add_rvalue_reference::type declval_U(); // workaround gcc bug; not required by std static typename add_rvalue_reference::type declval_b(); public: - typedef BOOST_TYPEOF_TPL(declval_b() ? declval_T() : declval_U()) type; + typedef typename std_decay::type type; #endif #if defined(__GNUC__) && __GNUC__ == 3 && __GNUC_MINOR__ == 3 @@ -123,7 +134,7 @@ namespace type_traits_detail { template struct common_type_2 { - typedef T type; + typedef typename type_traits_detail::std_decay::type type; }; } diff --git a/test/common_type_test.cpp b/test/common_type_test.cpp index 111cbb1..047b65f 100644 --- a/test/common_type_test.cpp +++ b/test/common_type_test.cpp @@ -211,5 +211,11 @@ TT_TEST_BEGIN(common_type) #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE4(tt::common_type::type, boost::long_long_type); #endif + + //changes related to defect LWG2141 + BOOST_CHECK_TYPE(tt::common_type::type, int); + BOOST_CHECK_TYPE(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, int); + BOOST_CHECK_TYPE3(tt::common_type::type, long); } TT_TEST_END