Skip to content

Commit

Permalink
Clean prev source_loc impl leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Nov 29, 2024
1 parent c7fc302 commit 6ea6b06
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 39 deletions.
21 changes: 0 additions & 21 deletions include/spdlog/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,29 +202,8 @@ class SPDLOG_API spdlog_ex : public std::exception {
};

[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno);

[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg);

// trick to capture format string and caller's source location with variadic template.
// see logger::info() etc. to understand how it's used.
struct loc_with_fmt {
source_loc loc;
string_view_t fmt_string;

template <typename S, typename = is_convertible_to_sv<S>>
constexpr loc_with_fmt(S fmt_str, source_loc loc = source_loc::current()) noexcept
: loc(loc),
fmt_string(fmt_str) {}

#ifndef SPDLOG_USE_STD_FORMAT

constexpr loc_with_fmt(fmt::runtime_format_string<char> fmt_str, source_loc loc = source_loc::current()) noexcept
: loc(loc),
fmt_string(fmt_str.str) {}

#endif
};

struct file_event_handlers {
file_event_handlers()
: before_open(nullptr),
Expand Down
16 changes: 1 addition & 15 deletions include/spdlog/source_loc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ struct source_loc {
short_filename{basename(filename_in)},
line{line_in},
funcname{funcname_in} {}

#ifdef SPDLOG_HAVE_STD_SOURCE_LOCATION
static constexpr source_loc current(const std::source_location source_location = std::source_location::current()) {
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
}
#elif defined(SPDLOG_HAVE_EXPERIMENTAL_SOURCE_LOCATION)
static constexpr source_loc current(
const std::experimental::source_location source_location = std::experimental::source_location::current()) {
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
}
#else // no source location support
static constexpr source_loc current() { return source_loc{}; }
#endif

[[nodiscard]] constexpr bool empty() const noexcept { return line == 0 || filename == nullptr || short_filename == nullptr; }

const char *filename{nullptr};
Expand All @@ -64,4 +50,4 @@ struct source_loc {
return file;
}
};
} // namespace spdlog
} // namespace spdlog
3 changes: 0 additions & 3 deletions tests/test_source_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ TEST_CASE("test_source_location", "[source_location]") {
REQUIRE(test_sink->lines().size() == 2);
REQUIRE(test_sink->lines()[1] == "test_source_location.cpp:18 Hello");
}


//REQUIRE(oss.str() == std::string("test_source_location.cpp:20 Hello source location") + default_eol);

0 comments on commit 6ea6b06

Please sign in to comment.