1 | // Copyright 2022 Peter Dimov |
---|---|
2 | // Distributed under the Boost Software License, Version 1.0. |
3 | // http://www.boost.org/LICENSE_1_0.txt |
4 | |
5 | #include <boost/assert/source_location.hpp> |
6 | #include <boost/core/lightweight_test.hpp> |
7 | #include <boost/config.hpp> |
8 | #include <cstring> |
9 | |
10 | static char const* adjust_filename( char const* file ) |
11 | { |
12 | #if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20210300 |
13 | |
14 | char const* fn = std::strrchr( file, '/' ); |
15 | return fn? fn + 1: file; |
16 | |
17 | #else |
18 | |
19 | return file; |
20 | |
21 | #endif |
22 | } |
23 | |
24 | boost::source_location s_loc = BOOST_CURRENT_LOCATION; |
25 | |
26 | BOOST_STATIC_CONSTEXPR boost::source_location c_loc = BOOST_CURRENT_LOCATION; |
27 | |
28 | boost::source_location f( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) |
29 | { |
30 | return loc; |
31 | } |
32 | |
33 | int main() |
34 | { |
35 | { |
36 | BOOST_TEST_CSTR_EQ( s_loc.file_name(), adjust_filename(__FILE__) ); |
37 | BOOST_TEST_EQ( s_loc.line(), 24 ); |
38 | |
39 | #if defined(BOOST_GCC) && BOOST_GCC < 90000 |
40 | // '__static_initialization_and_destruction_0' |
41 | #else |
42 | BOOST_TEST_CSTR_EQ( s_loc.function_name(), ""); |
43 | #endif |
44 | } |
45 | |
46 | { |
47 | BOOST_TEST_CSTR_EQ( c_loc.file_name(), adjust_filename(__FILE__) ); |
48 | BOOST_TEST_EQ( c_loc.line(), 26 ); |
49 | } |
50 | |
51 | { |
52 | boost::source_location loc = f(); |
53 | |
54 | BOOST_TEST_CSTR_EQ( loc.file_name(), adjust_filename(__FILE__) ); |
55 | BOOST_TEST( loc.line() == 28 || loc.line() == 52 ); |
56 | } |
57 | |
58 | return boost::report_errors(); |
59 | } |
60 |