2 * Copyright Andrey Semashev 2007 - 2013.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file explicit_operator_bool_noexcept.cpp
9 * \author Andrey Semashev
12 * \brief This test checks that explicit operator bool is noexcept when possible.
15 #define BOOST_TEST_MODULE explicit_operator_bool_noexcept
17 #include <boost/config.hpp>
19 #if !defined(BOOST_NO_CXX11_NOEXCEPT)
21 #include <boost/detail/lightweight_test.hpp>
22 #include <boost/utility/explicit_operator_bool.hpp>
28 BOOST_EXPLICIT_OPERATOR_BOOL()
29 bool operator! () const
37 BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()
38 BOOST_CONSTEXPR bool operator! () const
44 struct noexcept_checkable1
46 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
47 bool operator! () const noexcept
53 struct noexcept_checkable2
55 BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()
56 BOOST_CONSTEXPR bool operator! () const noexcept
64 int main(int, char*[])
69 noexcept_checkable1 noexcept_val1;
70 noexcept_checkable2 noexcept_val2;
72 BOOST_TEST(!noexcept(static_cast< bool >(val1)));
73 // constexpr functions are implicitly noexcept
74 BOOST_TEST(noexcept(static_cast< bool >(val2)));
76 BOOST_TEST(noexcept(static_cast< bool >(noexcept_val1)));
77 BOOST_TEST(noexcept(static_cast< bool >(noexcept_val2)));
79 return boost::report_errors();
84 int main(int, char*[])