fixed src_location namings and added macros for msvc

pull/2690/head
M. Galib Uludag 2 years ago
parent fd995f4c51
commit 1d24268488

@ -112,18 +112,12 @@
catch (const std::exception &) {} catch (const std::exception &) {}
#endif #endif
#ifdef _MSC_VER
#define SPDLOG_CPLUSPLUS _MSVC_LANG
#else
#define SPDLOG_CPLUSPLUS __cplusplus
#endif
#if SPDLOG_CPLUSPLUS > 201703L #if SPDLOG_CPLUSPLUS > 201703L
#define SPDLOG_CONSTEVAL consteval # define SPDLOG_CONSTEVAL consteval
#elif SPDLOG_CPLUSPLUS < 201402L #elif SPDLOG_CPLUSPLUS < 201402L
#define SPDLOG_CONSTEVAL # define SPDLOG_CONSTEVAL
#else #else
#define SPDLOG_CONSTEVAL constexpr # define SPDLOG_CONSTEVAL constexpr
#endif #endif
namespace spdlog { namespace spdlog {
@ -167,11 +161,6 @@ struct format_string_wrapper
: fmt_{fmtstr} : fmt_{fmtstr}
, loc_{loc} , loc_{loc}
{} {}
#elif !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION < 80000
SPDLOG_CONSTEXPR format_string_wrapper(const Char* fmtstr, details::source_location loc = details::source_location::current())
: fmt_{fmtstr}
, loc_{loc}
{}
#else #else
template <typename S> template <typename S>
requires std::is_convertible_v<S, T> requires std::is_convertible_v<S, T>

@ -4,8 +4,14 @@
#include <cstdint> #include <cstdint>
#ifdef _MSC_VER
# define SPDLOG_CPLUSPLUS _MSVC_LANG
#else
# define SPDLOG_CPLUSPLUS __cplusplus
#endif
#ifdef __has_include #ifdef __has_include
# if __has_include(<source_location>) && __cplusplus >= 202002L # if __has_include(<source_location>) && SPDLOG_CPLUSPLUS >= 202002L
# include <source_location> # include <source_location>
# define SPDLOG_SOURCE_LOCATION # define SPDLOG_SOURCE_LOCATION
# endif # endif
@ -23,57 +29,57 @@ public:
#if !defined(__apple_build_version__) && defined(__clang__) && \ #if !defined(__apple_build_version__) && defined(__clang__) && \
(__clang_major__ >= 9) (__clang_major__ >= 9)
static constexpr source_location static constexpr source_location
current(const char *fileName = __builtin_FILE(), current(const char *file = __builtin_FILE(),
const unsigned lineNumber = __builtin_LINE(), const unsigned line = __builtin_LINE(),
const char *functionName = __builtin_FUNCTION(), const char *function = __builtin_FUNCTION(),
const unsigned columnOffset = __builtin_COLUMN()) noexcept const unsigned column = __builtin_COLUMN()) noexcept
#elif defined(__GNUC__) && \ #elif defined(__GNUC__) && \
(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)) (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
static constexpr source_location static constexpr source_location
current(const char *fileName = __builtin_FILE(), current(const char *file = __builtin_FILE(),
const unsigned lineNumber = __builtin_LINE(), const unsigned line = __builtin_LINE(),
const char *functionName = __builtin_FUNCTION(), const char *function = __builtin_FUNCTION(),
const unsigned columnOffset = 0) noexcept const unsigned column = 0) noexcept
#elif defined(_MSC_VER) && (_MSC_VER > 1925) #elif defined(_MSC_VER) && (_MSC_VER > 1925)
static constexpr source_location static constexpr source_location
current(const char *fileName = __builtin_FILE(), current(const char *file = __builtin_FILE(),
const unsigned lineNumber = __builtin_LINE(), const unsigned line = __builtin_LINE(),
const char *functionName = __builtin_FUNCTION(), const char *function = __builtin_FUNCTION(),
const unsigned columnOffset = __builtin_COLUMN()) noexcept const unsigned column = __builtin_COLUMN()) noexcept
#else #else
static constexpr source_location static constexpr source_location
current(const char *fileName = "unsupported", current(const char *file = nullptr,
const unsigned lineNumber = 0, const unsigned line = 0,
const char *functionName = "unsupported", const char *function = nullptr,
const unsigned columnOffset = 0) noexcept const unsigned column = 0) noexcept
#endif #endif
{ {
return source_location(fileName, lineNumber, functionName, columnOffset); return source_location(file, line, function, column);
} }
source_location(const source_location &) = default; source_location(const source_location &) = default;
source_location(source_location &&) = default; source_location(source_location &&) = default;
constexpr const char *file_name() const noexcept { return fileName; } constexpr const char *file_name() const noexcept { return file_; }
constexpr const char *function_name() const noexcept { return functionName; } constexpr const char *function_name() const noexcept { return function_; }
constexpr unsigned line() const noexcept { return lineNumber; } constexpr unsigned line() const noexcept { return line_; }
constexpr unsigned column() const noexcept { return columnOffset; } constexpr unsigned column() const noexcept { return column_; }
private: private:
constexpr source_location(const char *fileName, constexpr source_location(const char *file,
const unsigned lineNumber, const unsigned line,
const char *functionName, const char *function,
const unsigned columnOffset) noexcept const unsigned column) noexcept
: fileName(fileName), lineNumber(lineNumber), functionName(functionName), : file_(file), line_(line), function_(function),
columnOffset(columnOffset) {} column_(column) {}
const char *fileName; const char *file_;
const unsigned lineNumber; const unsigned line_;
const char *functionName; const char *function_;
const unsigned columnOffset; const unsigned column_;
}; };
} // namespace details } // namespace details
} // namespace spdlog } // namespace spdlog

Loading…
Cancel
Save