From 762a98d2276ac7b30caad62e6c65b041700555cb Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 4 Feb 2022 02:07:36 +0200 Subject: [PATCH] Use __builtin_FILE et al in BOOST_CURRENT_LOCATION --- include/boost/assert/source_location.hpp | 30 ++++++++---------------- test/source_location_test4.cpp | 13 +--------- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/include/boost/assert/source_location.hpp b/include/boost/assert/source_location.hpp index abc029a..fabce91 100644 --- a/include/boost/assert/source_location.hpp +++ b/include/boost/assert/source_location.hpp @@ -123,37 +123,27 @@ template std::basic_ostream & 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 diff --git a/test/source_location_test4.cpp b/test/source_location_test4.cpp index 35c78b5..dd053fe 100644 --- a/test/source_location_test4.cpp +++ b/test/source_location_test4.cpp @@ -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();