1/*
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)
6 */
7/*!
8 * \file explicit_operator_bool_noexcept.cpp
9 * \author Andrey Semashev
10 * \date 26.04.2014
11 *
12 * \brief This test checks that explicit operator bool is noexcept when possible.
13 */
14
15#define BOOST_TEST_MODULE explicit_operator_bool_noexcept
16
17#include <boost/config.hpp>
18
19#if !defined(BOOST_NO_CXX11_NOEXCEPT)
20
21#include <boost/core/lightweight_test.hpp>
22#include <boost/utility/explicit_operator_bool.hpp>
23
24namespace {
25
26 struct checkable1
27 {
28 BOOST_EXPLICIT_OPERATOR_BOOL()
29 bool operator! () const
30 {
31 return false;
32 }
33 };
34
35 struct checkable2
36 {
37 BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()
38 BOOST_CONSTEXPR bool operator! () const
39 {
40 return false;
41 }
42 };
43
44 struct noexcept_checkable1
45 {
46 BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
47 bool operator! () const noexcept
48 {
49 return false;
50 }
51 };
52
53 struct noexcept_checkable2
54 {
55 BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()
56 BOOST_CONSTEXPR bool operator! () const noexcept
57 {
58 return false;
59 }
60 };
61
62} // namespace
63
64int main(int, char*[])
65{
66 checkable1 val1;
67 checkable2 val2;
68
69 noexcept_checkable1 noexcept_val1;
70 noexcept_checkable2 noexcept_val2;
71
72 BOOST_TEST(!noexcept(static_cast< bool >(val1)));
73 // constexpr functions are implicitly noexcept
74 BOOST_TEST(noexcept(static_cast< bool >(val2)));
75
76 BOOST_TEST(noexcept(static_cast< bool >(noexcept_val1)));
77 BOOST_TEST(noexcept(static_cast< bool >(noexcept_val2)));
78
79 (void)val1;
80 (void)val2;
81 (void)noexcept_val1;
82 (void)noexcept_val2;
83
84 return boost::report_errors();
85}
86
87#else
88
89int main(int, char*[])
90{
91 return 0;
92}
93
94#endif
95

source code of boost/libs/core/test/explicit_operator_bool_noexcept.cpp