]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/throw_exception/test/throw_with_location_test2.cpp
1 // Copyright 2022 Peter Dimov
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt
5 #include <boost/throw_exception.hpp>
6 #include <boost/core/lightweight_test.hpp>
9 # pragma warning(disable: 4702) // unreachable code
12 class my_exception
: public std::exception
20 boost::throw_with_location( my_exception() );
22 BOOST_ERROR( "boost::throw_with_location failed to throw" );
24 catch( std::exception
const & x
)
26 boost::source_location loc
= boost::get_throw_location( x
);
28 // When not supplied explicitly, the source location is best effort.
29 // It should be the location of the throw_with_location call on
30 // recent compilers, but that's not guaranteed for every compiler.
31 // So we can't be more specific in testing it.
33 BOOST_TEST_CSTR_NE( loc
.file_name(), "" );
34 BOOST_TEST_NE( loc
.line(), 0u );
38 BOOST_ERROR( "boost::throw_with_location failed to throw std::exception" );
41 boost::source_location location
= BOOST_CURRENT_LOCATION
;
45 boost::throw_with_location( my_exception(), location
);
47 BOOST_ERROR( "boost::throw_with_location failed to throw" );
49 catch( std::exception
const & x
)
51 boost::source_location loc
= boost::get_throw_location( x
);
53 BOOST_TEST_CSTR_EQ( loc
.file_name(), location
.file_name() );
54 BOOST_TEST_CSTR_EQ( loc
.function_name(), location
.function_name() );
55 BOOST_TEST_EQ( loc
.line(), location
.line() );
56 BOOST_TEST_EQ( loc
.column(), location
.column() );
60 BOOST_ERROR( "boost::throw_with_location failed to throw std::exception" );
63 return boost::report_errors();