Use __builtin_FILE et al in BOOST_CURRENT_LOCATION

This commit is contained in:
Peter Dimov
2022-02-04 02:07:36 +02:00
parent 1a80da6298
commit 762a98d227
2 changed files with 11 additions and 32 deletions

View File

@@ -123,37 +123,27 @@ template<class E, class T> std::basic_ostream<E, T> & operator<<( std::basic_ost
return os;
}
namespace detail
{
inline char const* srcloc_strip_top_level( char const* fn )
{
return std::strcmp( fn, "top level" ) == 0? "": fn;
}
} // namespace detail
} // namespace boost
#if defined( BOOST_DISABLE_CURRENT_LOCATION )
#if defined(BOOST_DISABLE_CURRENT_LOCATION)
# define BOOST_CURRENT_LOCATION ::boost::source_location()
#elif defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L && !BOOST_WORKAROUND(BOOST_MSVC, < 1931)
#elif defined(BOOST_MSVC) && BOOST_MSVC >= 1926
# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN())
#elif defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L
# define BOOST_CURRENT_LOCATION ::boost::source_location(::std::source_location::current())
#elif defined(BOOST_DISABLE_CURRENT_FUNCTION) || defined(__clang_analyzer__) // https://bugs.llvm.org/show_bug.cgi?id=28480
#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION >= 90000
# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, "")
# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN())
#elif defined(__GNUC__) || defined(__clang__)
#elif defined(BOOST_GCC) && BOOST_GCC >= 40800
# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, ::boost::detail::srcloc_strip_top_level(__PRETTY_FUNCTION__))
# if defined(__clang__)
# pragma clang diagnostic ignored "-Wpredefined-identifier-outside-function"
# endif
# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION())
#else

View File

@@ -23,19 +23,8 @@ int main()
{
boost::source_location loc = f();
#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L && !BOOST_WORKAROUND(BOOST_MSVC, < 1931)
BOOST_TEST_CSTR_EQ( loc.file_name(), std::source_location::current().file_name() );
BOOST_TEST_CSTR_EQ( loc.function_name(), std::source_location::current().function_name() );
BOOST_TEST_EQ( loc.line(), 24 );
#else
BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ );
BOOST_TEST_EQ( loc.line(), 10 );
BOOST_TEST_CSTR_EQ( loc.function_name(), "" );
#endif
BOOST_TEST( loc.line() == 10 || loc.line() == 24 );
}
return boost::report_errors();