forked from boostorg/logic
omit unnecessary bits when explicit operator conversions are supported
This commit is contained in:
+22
-5
@@ -3,7 +3,7 @@
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include <boost/test/minimal.hpp>
|
||||
#include <iostream>
|
||||
@@ -16,6 +16,19 @@ int test_main(int, char*[])
|
||||
tribool y(true); // true
|
||||
tribool z(indeterminate); // indeterminate
|
||||
|
||||
#if defined( BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS )
|
||||
// c++03 allows for implicit conversion to bool
|
||||
// c++11 uses an explicit conversion operator so this would not compile
|
||||
// and that is tested in the compile-fail/implicit.cpp file
|
||||
// so we check the conversion to ensure it is sane
|
||||
bool bx = x;
|
||||
BOOST_CHECK(bx == false);
|
||||
bool by = y;
|
||||
BOOST_CHECK(by == true);
|
||||
bool bz = z;
|
||||
BOOST_CHECK(bz == false);
|
||||
#endif
|
||||
|
||||
BOOST_CHECK(!x);
|
||||
BOOST_CHECK(x == false);
|
||||
BOOST_CHECK(false == x);
|
||||
@@ -115,7 +128,7 @@ int test_main(int, char*[])
|
||||
BOOST_CHECK(false);
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_CXX11_CONSTEXPR
|
||||
#if !defined(BOOST_NO_CXX11_CONSTEXPR)
|
||||
constexpr bool res_ors = indeterminate(false || tribool(false) || false || indeterminate); // true
|
||||
BOOST_CHECK(res_ors);
|
||||
char array_ors[res_ors ? 2 : 3];
|
||||
@@ -127,9 +140,13 @@ int test_main(int, char*[])
|
||||
BOOST_CHECK(sizeof(array_ands) / sizeof(char) == 3);
|
||||
|
||||
constexpr bool res_safe_bool = static_cast<bool>( tribool(true) );
|
||||
boost::ignore_unused(res_safe_bool);
|
||||
constexpr tribool xxx = (tribool(true) || tribool(indeterminate));
|
||||
static_assert(xxx, "Must be true!");
|
||||
BOOST_STATIC_ASSERT(res_safe_bool);
|
||||
|
||||
// gcc 4.6 chokes on the xxx assignment
|
||||
# if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
|
||||
constexpr tribool xxx = (tribool(true) || tribool(indeterminate));
|
||||
BOOST_STATIC_ASSERT(xxx);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
std::cout << "no errors detected\n";
|
||||
|
||||
Reference in New Issue
Block a user