[Boost-bugs] [Boost C++ Libraries] #2827: boost::detail::is_abstract_imp2::s1: 64 bit truncation warning

Subject: [Boost-bugs] [Boost C++ Libraries] #2827: boost::detail::is_abstract_imp2::s1: 64 bit truncation warning
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-03-03 22:50:13


#2827: boost::detail::is_abstract_imp2::s1: 64 bit truncation warning
----------------------------------+-----------------------------------------
 Reporter: pelee_at_[hidden] | Owner: johnmaddock
     Type: Bugs | Status: new
Milestone: Boost 1.39.0 | Component: type_traits
  Version: Boost Release Branch | Severity: Problem
 Keywords: |
----------------------------------+-----------------------------------------
 The constant detail::is_abstract_imp2::s1 is declared as unsigned, but
 initialized to the result of sizeof(). sizeof() returns a 64 bit value
 when compiled on a 64 bit target. This causes a 64-to-32 bit truncation
 warning on 64 bit targets.

 One option would be to declare the constant to be of type size_t. I opted
 instead for a static_cast on the assumption that it would cause less
 disruption and that the sizeof() call in question would probably never
 return a value that required more than 32 bits.


 {{{
 template<class T>
 struct is_abstract_imp2
 {
    // Deduction fails if T is void, function type,
    // reference type (14.8.2/2)or an abstract class type
    // according to review status issue #337
    //
    template<class U>
    static type_traits::no_type check_sig(U (*)[1]);
    template<class U>
    static type_traits::yes_type check_sig(...);
    //
    // T must be a complete type, further if T is a template then
    // it must be instantiated in order for us to get the right answer:
    //
    BOOST_STATIC_ASSERT(sizeof(T) != 0);

    // GCC2 won't even parse this template if we embed the computation
    // of s1 in the computation of value.
 #ifdef __GNUC__
    BOOST_STATIC_CONSTANT(unsigned, s1 =
 static_cast<unsigned>(sizeof(is_abstract_imp2<T>::template
 check_sig<T>(0))));
 #else
 #if BOOST_WORKAROUND(_MSC_FULL_VER, >= 140050000)
 #pragma warning(push)
 #pragma warning(disable:6334)
 #endif
    BOOST_STATIC_CONSTANT(unsigned, s1 =
 static_cast<unsigned>(sizeof(check_sig<T>(0))));
 #if BOOST_WORKAROUND(_MSC_FULL_VER, >= 140050000)
 #pragma warning(pop)
 #endif
 #endif

    BOOST_STATIC_CONSTANT(bool, value =
       (s1 == sizeof(type_traits::yes_type)));
 };

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2827>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC