lg2: simplify source_location for clang-16
As of clang-16, `source_location` is fully supported, so we do not need
to use the `experimental::source_location` workarounds anymore.
Eliminate them and use `std::source_location` directly rather than the
`lg2::source_location` alias.
Tested: Compiled the repository with CXX=clang++.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Iba987ed9580d228781acac630681fda172a6cef7
diff --git a/lib/include/phosphor-logging/lg2.hpp b/lib/include/phosphor-logging/lg2.hpp
index 658c591..ad0d39d 100644
--- a/lib/include/phosphor-logging/lg2.hpp
+++ b/lib/include/phosphor-logging/lg2.hpp
@@ -9,12 +9,13 @@
#include <phosphor-logging/lg2/flags.hpp>
#include <phosphor-logging/lg2/header.hpp>
#include <phosphor-logging/lg2/level.hpp>
-#include <phosphor-logging/lg2/source_location.hpp>
+
+#include <source_location>
namespace lg2
{
/** Implementation of the structured logging `lg2::log` interface. */
-template <level S = level::debug, details::any_but<lg2::source_location>... Ts>
+template <level S = level::debug, details::any_but<std::source_location>... Ts>
struct log
{
/** log with a custom source_location.
@@ -23,7 +24,7 @@
* @param[in] msg - The message to log.
* @param[in] ts - The rest of the arguments.
*/
- explicit log(const lg2::source_location& s, const char* msg,
+ explicit log(const std::source_location& s, const char* msg,
details::header_str_conversion_t<Ts&&>... ts)
{
details::log_conversion::start(
@@ -39,7 +40,7 @@
*/
explicit log(
const char* msg, details::header_str_conversion_t<Ts&&>... ts,
- const lg2::source_location& s = lg2::source_location::current()) :
+ const std::source_location& s = std::source_location::current()) :
log(s, msg, std::forward<details::header_str_conversion_t<Ts&&>>(ts)...)
{}
@@ -53,7 +54,7 @@
explicit log(const char*, Ts&&...) -> log<S, Ts...>;
template <level S = level::debug, typename... Ts>
-explicit log(const lg2::source_location&, const char*, Ts&&...)
+explicit log(const std::source_location&, const char*, Ts&&...)
-> log<S, Ts...>;
/** Macro to define aliases for lg2::level(...) -> lg2::log<level>(...)
@@ -71,7 +72,7 @@
explicit levelval(const char*, Ts&&...) -> levelval<Ts...>; \
\
template <typename... Ts> \
- explicit levelval(const lg2::source_location&, const char*, Ts&&...) \
+ explicit levelval(const std::source_location&, const char*, Ts&&...) \
->levelval<Ts...>
// Enumerate the aliases for each log level.
diff --git a/lib/include/phosphor-logging/lg2/conversion.hpp b/lib/include/phosphor-logging/lg2/conversion.hpp
index 373fbe4..92265e7 100644
--- a/lib/include/phosphor-logging/lg2/conversion.hpp
+++ b/lib/include/phosphor-logging/lg2/conversion.hpp
@@ -4,12 +4,12 @@
#include <phosphor-logging/lg2/header.hpp>
#include <phosphor-logging/lg2/level.hpp>
#include <phosphor-logging/lg2/logger.hpp>
-#include <phosphor-logging/lg2/source_location.hpp>
#include <sdbusplus/message/native_types.hpp>
#include <concepts>
#include <cstddef>
#include <filesystem>
+#include <source_location>
#include <string_view>
#include <tuple>
#include <type_traits>
@@ -286,7 +286,7 @@
/** Conversion and validation is complete. Pass along to the final
* do_log variadic function. */
template <typename... Ts>
- static void done(level l, const lg2::source_location& s, const char* m,
+ static void done(level l, const std::source_location& s, const char* m,
Ts&&... ts)
{
do_log(l, s, m, ts..., nullptr);
@@ -398,7 +398,7 @@
/** Start processing a sequence of arguments to `lg2::log` using `step` or
* `done`. */
template <typename... Ts>
- static void start(level l, const lg2::source_location& s, const char* msg,
+ static void start(level l, const std::source_location& s, const char* msg,
Ts&&... ts)
{
// If there are no arguments (ie. just a message), then skip processing
diff --git a/lib/include/phosphor-logging/lg2/logger.hpp b/lib/include/phosphor-logging/lg2/logger.hpp
index 7762a5f..9044bfd 100644
--- a/lib/include/phosphor-logging/lg2/logger.hpp
+++ b/lib/include/phosphor-logging/lg2/logger.hpp
@@ -1,9 +1,9 @@
#pragma once
#include <phosphor-logging/lg2/level.hpp>
-#include <phosphor-logging/lg2/source_location.hpp>
#include <cstddef>
+#include <source_location>
namespace lg2::details
{
@@ -20,6 +20,6 @@
* log call.
* @param[in] char* - The primary message to log.
*/
-void do_log(level, const lg2::source_location&, const char*, ...);
+void do_log(level, const std::source_location&, const char*, ...);
} // namespace lg2::details
diff --git a/lib/include/phosphor-logging/lg2/source_location.hpp b/lib/include/phosphor-logging/lg2/source_location.hpp
index 9d2033b..813250d 100644
--- a/lib/include/phosphor-logging/lg2/source_location.hpp
+++ b/lib/include/phosphor-logging/lg2/source_location.hpp
@@ -1,27 +1,8 @@
#pragma once
-// As of clang-12, clang still doesn't support std::source_location, which
-// means that clang-tidy also doesn't support std::source_location.
-// Inside the libstdc++ implementation of <source_location> is this check of
-// __builtin_source_location to determine if the compiler supports the
-// necessary bits for std::source_location, and if not the header ends up doing
-// nothing. Use this same builtin-check to detect when we're running under
-// an "older" clang and fallback to std::experimental::source_location instead.
-
-#if __has_builtin(__builtin_source_location)
#include <source_location>
namespace lg2
{
using source_location = std::source_location;
}
-
-#else
-#include <experimental/source_location>
-
-namespace lg2
-{
-using source_location = std::experimental::source_location;
-}
-
-#endif
diff --git a/lib/include/phosphor-logging/meson.build b/lib/include/phosphor-logging/meson.build
index 8c477ad..2b166cb 100644
--- a/lib/include/phosphor-logging/meson.build
+++ b/lib/include/phosphor-logging/meson.build
@@ -29,7 +29,6 @@
'lg2/header.hpp',
'lg2/level.hpp',
'lg2/logger.hpp',
- 'lg2/source_location.hpp',
subdir: 'phosphor-logging/lg2',
)
diff --git a/lib/lg2_logger.cpp b/lib/lg2_logger.cpp
index a83dcb2..81f085d 100644
--- a/lib/lg2_logger.cpp
+++ b/lib/lg2_logger.cpp
@@ -10,19 +10,9 @@
#include <cstdarg>
#include <cstdio>
#include <iostream>
+#include <source_location>
#include <vector>
-// Clang doesn't currently support source_location, but in order to provide
-// support for compiling an application with Clang while lg2 was compiled with
-// GCC we need to provide compile support *both* source_location and
-// experimental::source_location.
-//
-// Note: The experimental::source_location code will turn into a no-op for
-// simplicity. This is simply to allow compilation.
-#if __has_builtin(__builtin_source_location)
-#include <experimental/source_location>
-#endif
-
namespace lg2::details
{
/** Convert unsigned to string using format flags. */
@@ -137,12 +127,12 @@
static constexpr size_t static_locs = pos_func + 1;
/** No-op output of a message. */
-static void noop_extra_output(level, const lg2::source_location&,
+static void noop_extra_output(level, const std::source_location&,
const std::string&)
{}
/** std::cerr output of a message. */
-static void cerr_extra_output(level l, const lg2::source_location& s,
+static void cerr_extra_output(level l, const std::source_location& s,
const std::string& m)
{
static const char* const defaultFormat = []() {
@@ -215,7 +205,7 @@
: noop_extra_output;
// Do_log implementation.
-void do_log(level l, const lg2::source_location& s, const char* m, ...)
+void do_log(level l, const std::source_location& s, const char* m, ...)
{
using namespace std::string_literals;
@@ -304,14 +294,4 @@
extra_output_method(l, s, message);
}
-// If std::source_location is supported, provide an additional
-// std::experimental::source_location implementation that does nothing so that
-// lg2 users can compile with Clang even if lg2 was compiled with GCC. This
-// is a no-op implementation that simply allows compile support since some
-// people like to compile with Clang for additional / stricter checks.
-#if __has_builtin(__builtin_source_location)
-void do_log(level, const std::experimental::source_location&, const char*, ...)
-{}
-#endif
-
} // namespace lg2::details