]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/assert/source_location.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / assert / source_location.hpp
1 #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED
2 #define BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED
3
4 // http://www.boost.org/libs/assert
5 //
6 // Copyright 2019, 2021 Peter Dimov
7 // Distributed under the Boost Software License, Version 1.0.
8 // http://www.boost.org/LICENSE_1_0.txt
9
10 #include <boost/current_function.hpp>
11 #include <boost/config.hpp>
12 #include <boost/config/workaround.hpp>
13 #include <boost/cstdint.hpp>
14 #include <iosfwd>
15 #include <string>
16 #include <cstdio>
17 #include <cstring>
18
19 #if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L
20 # include <source_location>
21 #endif
22
23 namespace boost
24 {
25
26 struct source_location
27 {
28 private:
29
30 char const * file_;
31 char const * function_;
32 boost::uint_least32_t line_;
33 boost::uint_least32_t column_;
34
35 public:
36
37 BOOST_CONSTEXPR source_location() BOOST_NOEXCEPT: file_( "" ), function_( "" ), line_( 0 ), column_( 0 )
38 {
39 }
40
41 BOOST_CONSTEXPR source_location( char const * file, boost::uint_least32_t ln, char const * function, boost::uint_least32_t col = 0 ) BOOST_NOEXCEPT: file_( file ), function_( function ), line_( ln ), column_( col )
42 {
43 }
44
45 #if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L
46
47 BOOST_CONSTEXPR source_location( std::source_location const& loc ) BOOST_NOEXCEPT: file_( loc.file_name() ), function_( loc.function_name() ), line_( loc.line() ), column_( loc.column() )
48 {
49 }
50
51 #endif
52
53 BOOST_CONSTEXPR char const * file_name() const BOOST_NOEXCEPT
54 {
55 return file_;
56 }
57
58 BOOST_CONSTEXPR char const * function_name() const BOOST_NOEXCEPT
59 {
60 return function_;
61 }
62
63 BOOST_CONSTEXPR boost::uint_least32_t line() const BOOST_NOEXCEPT
64 {
65 return line_;
66 }
67
68 BOOST_CONSTEXPR boost::uint_least32_t column() const BOOST_NOEXCEPT
69 {
70 return column_;
71 }
72
73 #if defined(BOOST_MSVC)
74 # pragma warning( push )
75 # pragma warning( disable: 4996 )
76 #endif
77
78 std::string to_string() const
79 {
80 unsigned long ln = line();
81
82 if( ln == 0 )
83 {
84 return "(unknown source location)";
85 }
86
87 std::string r = file_name();
88
89 char buffer[ 16 ];
90
91 std::sprintf( buffer, ":%lu", ln );
92 r += buffer;
93
94 unsigned long co = column();
95
96 if( co )
97 {
98 std::sprintf( buffer, ":%lu", co );
99 r += buffer;
100 }
101
102 char const* fn = function_name();
103
104 if( *fn != 0 )
105 {
106 r += " in function '";
107 r += fn;
108 r += '\'';
109 }
110
111 return r;
112 }
113
114 #if defined(BOOST_MSVC)
115 # pragma warning( pop )
116 #endif
117
118 };
119
120 template<class E, class T> std::basic_ostream<E, T> & operator<<( std::basic_ostream<E, T> & os, source_location const & loc )
121 {
122 os << loc.to_string();
123 return os;
124 }
125
126 } // namespace boost
127
128 #if defined(BOOST_DISABLE_CURRENT_LOCATION)
129
130 # define BOOST_CURRENT_LOCATION ::boost::source_location()
131
132 #elif defined(BOOST_MSVC) && BOOST_MSVC >= 1926
133
134 // std::source_location::current() is available in -std:c++20, but fails with consteval errors before 19.31, and doesn't produce
135 // the correct result under 19.31, so prefer the built-ins
136 # define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN())
137
138 #elif defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L
139
140 # define BOOST_CURRENT_LOCATION ::boost::source_location(::std::source_location::current())
141
142 #elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION >= 90000
143
144 # define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN())
145
146 #elif defined(BOOST_GCC) && BOOST_GCC >= 70000
147
148 // The built-ins are available in 4.8+, but are not constant expressions until 7
149 # define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION())
150
151 #elif defined(BOOST_GCC) && BOOST_GCC >= 50000
152
153 // __PRETTY_FUNCTION__ is allowed outside functions under GCC, but 4.x suffers from codegen bugs
154 # define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, __PRETTY_FUNCTION__)
155
156 #else
157
158 // __func__ macros aren't allowed outside functions, but BOOST_CURRENT_LOCATION is
159 # define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, "")
160
161 #endif
162
163 #endif // #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED