// common_type_test.cpp ----------------------------------------------------// // Copyright 2010 Beman Dawes // Distributed under the Boost Software License, Version 1.0. // See http://www.boost.org/LICENSE_1_0.txt #ifdef TEST_STD # include #else # include #endif #include "test.hpp" #include "check_type.hpp" #include #ifdef BOOST_INTEL #pragma warning(disable: 304 383) #endif struct C1 {}; struct C2 {}; struct C3 : C2 {}; struct C1C2 { C1C2() {} C1C2(C1 const&) {} C1C2(C2 const&) {} C1C2& operator=(C1C2 const&) { return *this; } }; template void proc2(typename boost::common_type::type const& ) {} template void proc3(typename boost::common_type::type const& ) {} template void assignation_2() { typedef typename boost::common_type::type AC; A a; C c; AC ac; ac=a; ac=c; proc2(a); proc2(c); } template void assignation_3() { typedef typename boost::common_type::type ABC; A a; B b; C c; ABC abc; abc=a; abc=b; abc=c; proc3(a); proc3(b); proc3(c); } C1C2 c1c2; C1 c1; int f(C1C2 ) { return 1;} int f(C1 ) { return 2;} template OSTREAM& operator<<(OSTREAM& os, C1 const&) {return os;} C1C2& declval_C1C2() {return c1c2;} C1& declval_C1(){return c1;} bool declval_bool(){return true;} TT_TEST_BEGIN(common_type) { assignation_2(); typedef tt::common_type::type T1; BOOST_CHECK_TYPE(T1, C1C2); typedef tt::common_type::type T2; BOOST_CHECK_TYPE(T2, C2*); typedef tt::common_type::type T3; BOOST_CHECK_TYPE(T3, int const*); #if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) // fails if BOOST_COMMON_TYPE_DONT_USE_TYPEOF: typedef tt::common_type::type T4; BOOST_CHECK_TYPE(T4, int const volatile*); #endif typedef tt::common_type::type T5; BOOST_CHECK_TYPE(T5, int volatile*); assignation_2(); assignation_2(); assignation_2(); assignation_3(); assignation_3(); assignation_3(); assignation_3(); //assignation_3(); // fails because the common type is the third BOOST_CHECK_TYPE(tt::common_type::type, int); BOOST_CHECK_TYPE(tt::common_type::type, char); BOOST_CHECK_TYPE3(tt::common_type::type, char); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); #endif BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned char); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); #endif BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, short); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); #endif BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned short); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); #endif BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); #endif BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); BOOST_CHECK_TYPE3(tt::common_type::type, unsigned int); #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); #endif BOOST_CHECK_TYPE3(tt::common_type::type, double); #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::long_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, boost::ulong_long_type); BOOST_CHECK_TYPE3(tt::common_type::type, double); #endif BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, double); #ifndef BOOST_NO_LONG_LONG BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE3(tt::common_type::type, double); #endif BOOST_CHECK_TYPE3(tt::common_type::type, double); BOOST_CHECK_TYPE4(tt::common_type::type, double); #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