I’m not sure we should replace all std::source_location usage. There is value in uniformity, but I think it’s also good to keep places that don’t require the shorter function name to stick with stdlib? This is fairly trivial to achieve with e.g.:
0diff --git a/src/logging.cpp b/src/logging.cpp
1index b5baac0721..b321991930 100644
2--- a/src/logging.cpp
3+++ b/src/logging.cpp
4@@ -388,7 +388,7 @@ std::shared_ptr<BCLog::LogRateLimiter> BCLog::LogRateLimiter::Create(
5 }
6
7 BCLog::LogRateLimiter::Status BCLog::LogRateLimiter::Consume(
8- const SourceLocation& source_loc,
9+ const std::source_location& source_loc,
10 const std::string& str)
11 {
12 StdLockGuard scoped_lock(m_mutex);
13diff --git a/src/logging.h b/src/logging.h
14index 8c276d4606..f0eb23c48e 100644
15--- a/src/logging.h
16+++ b/src/logging.h
17@@ -51,6 +51,7 @@ public:
18 std::string_view file_name() const { return m_loc.file_name(); }
19 std::uint_least32_t line() const { return m_loc.line(); }
20 std::string_view function_name() const { return m_func; }
21+ operator const std::source_location&(){ return m_loc; };
22
23 private:
24 std::string_view m_func;
25@@ -58,14 +59,14 @@ private:
26 };
27
28 struct SourceLocationEqual {
29- bool operator()(const SourceLocation& lhs, const SourceLocation& rhs) const noexcept
30+ bool operator()(const std::source_location& lhs, const std::source_location& rhs) const noexcept
31 {
32 return lhs.line() == rhs.line() && std::string_view(lhs.file_name()) == std::string_view(rhs.file_name());
33 }
34 };
35
36 struct SourceLocationHasher {
37- size_t operator()(const SourceLocation& s) const noexcept
38+ size_t operator()(const std::source_location& s) const noexcept
39 {
40 // Use CSipHasher(0, 0) as a simple way to get uniform distribution.
41 return size_t(CSipHasher(0, 0)
42@@ -151,7 +152,7 @@ namespace BCLog {
43 mutable StdMutex m_mutex;
44
45 //! Stats for each source location that has attempted to log something.
46- std::unordered_map<SourceLocation, Stats, SourceLocationHasher, SourceLocationEqual> m_source_locations GUARDED_BY(m_mutex);
47+ std::unordered_map<std::source_location, Stats, SourceLocationHasher, SourceLocationEqual> m_source_locations GUARDED_BY(m_mutex);
48 //! Whether any log locations are suppressed. Cached view on m_source_locations for performance reasons.
49 std::atomic<bool> m_suppression_active{false};
50 LogRateLimiter(uint64_t max_bytes, std::chrono::seconds reset_window);
51@@ -183,7 +184,7 @@ namespace BCLog {
52 //! Consumes `source_loc`'s available bytes corresponding to the size of the (formatted)
53 //! `str` and returns its status.
54 [[nodiscard]] Status Consume(
55- const SourceLocation& source_loc,
56+ const std::source_location& source_loc,
57 const std::string& str) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
58 //! Resets all usage to zero. Called periodically by the scheduler.
59 void Reset() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
With that diff (and perhaps without it too), it’s probably better to expose the abbreviated name under a different name, e.g. SourceLocation::function_name_short()?