]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/lexical_cast/test/no_exceptions_test.cpp
1 // Unit test for boost::lexical_cast.
3 // See http://www.boost.org for most recent version, including documentation.
5 // Copyright Antony Polukhin, 2012-2022.
7 // Distributed under the Boost
8 // Software License, Version 1.0. (See accompanying file
9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
11 #include <boost/config.hpp>
13 #if defined(__INTEL_COMPILER)
14 #pragma warning(disable: 193 383 488 981 1418 1419)
15 #elif defined(BOOST_MSVC)
16 #pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
19 #include <boost/lexical_cast.hpp>
20 #include <boost/core/lightweight_test.hpp>
21 #include <boost/range/iterator_range.hpp>
25 #include "escape_struct.hpp"
27 #ifndef BOOST_NO_EXCEPTIONS
28 #error "This test must be compiled with -DBOOST_NO_EXCEPTIONS"
33 BOOST_NORETURN
void throw_exception(std::exception
const & ) {
40 lexical_cast
<char>(v
); // should call boost::throw_exception
43 lexical_cast
<unsigned char>(v
); // should call boost::throw_exception
46 std::exit(boost::report_errors());
51 void test_exceptions_off() {
52 using namespace boost
;
55 v
= lexical_cast
<EscapeStruct
>(100);
56 BOOST_TEST_EQ(lexical_cast
<int>(v
), 100);
57 BOOST_TEST_EQ(lexical_cast
<unsigned int>(v
), 100u);
59 v
= lexical_cast
<EscapeStruct
>(0.0);
60 BOOST_TEST_EQ(lexical_cast
<double>(v
), 0.0);
62 BOOST_TEST_EQ(lexical_cast
<short>(100), 100);
63 BOOST_TEST_EQ(lexical_cast
<float>(0.0), 0.0);
65 lexical_cast
<short>(700000); // should call boost::throw_exception
70 test_exceptions_off();
72 return boost::report_errors();