From cb35191fc12537abe7cb0e02a598054a2372162b Mon Sep 17 00:00:00 2001 From: dkavolis <12998363+dkavolis@users.noreply.github.com> Date: Mon, 9 Aug 2021 09:20:59 +0100 Subject: [PATCH 1/2] clang is acting weird with disabled constructors --- include/spdlog/common.h | 23 +++++++++++++++++++---- include/spdlog/logger.h | 6 +++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 518da900..9a425464 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -116,6 +116,17 @@ using wstring_view_t = fmt::basic_string_view; using memory_buf_t = fmt::basic_memory_buffer; using wmemory_buf_t = fmt::basic_memory_buffer; +template +using remove_cvref_t = typename std::remove_cv::type>::type; + +// clang doesn't like SFINAE disabled constructor in std::is_convertible<> so have to repeat the condition from basic_format_string here, +// in addition, fmt::basic_runtime is only convertible to basic_format_string but not basic_string_view +template +struct is_convertible_to_basic_format_string + : std::integral_constant>::value || std::is_same, fmt::basic_runtime>::value> +{}; + #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT # ifndef _WIN32 # error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows @@ -123,9 +134,9 @@ using wmemory_buf_t = fmt::basic_memory_buffer; template struct is_convertible_to_wstring_view : std::is_convertible {}; + template -struct is_convertible_to_wformat_string : std::is_convertible> -{}; +using is_convertible_to_wformat_string = is_convertible_to_basic_format_string; # endif // _WIN32 #else template @@ -137,8 +148,12 @@ struct is_convertible_to_wformat_string : std::false_type #endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT template -struct is_convertible_to_basic_format_string - : std::integral_constant>::value || is_convertible_to_wformat_string::value> +struct is_convertible_to_any_string_view + : std::integral_constant::value || is_convertible_to_wstring_view::value> +{}; +template +struct is_convertible_to_any_format_string + : std::integral_constant::value || is_convertible_to_wformat_string::value> {}; #if defined(SPDLOG_NO_ATOMIC_LEVELS) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 2e58628f..1d23c5a6 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -103,9 +103,9 @@ public: } // T cannot be statically converted to neither string_view, nor wstring_view and nor format string - template::value && - !is_convertible_to_basic_format_string::value, - int>::type = 0> + template::value && !is_convertible_to_any_format_string::value, int>::type = 0> void log(source_loc loc, level::level_enum lvl, const T &msg) { log(loc, lvl, "{}", msg); From e471ec884eedd7ec665d4cd083ece0eeaf77f875 Mon Sep 17 00:00:00 2001 From: dkavolis <12998363+dkavolis@users.noreply.github.com> Date: Mon, 9 Aug 2021 17:33:00 +0100 Subject: [PATCH 2/2] remove conditional `is_convertible_*` structs for wide chars --- include/spdlog/common.h | 24 +++--------------------- include/spdlog/logger.h | 6 ++---- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/include/spdlog/common.h b/include/spdlog/common.h index 9a425464..ed0ab46c 100644 --- a/include/spdlog/common.h +++ b/include/spdlog/common.h @@ -130,30 +130,12 @@ struct is_convertible_to_basic_format_string #ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT # ifndef _WIN32 # error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows -# else -template -struct is_convertible_to_wstring_view : std::is_convertible -{}; - -template -using is_convertible_to_wformat_string = is_convertible_to_basic_format_string; # endif // _WIN32 -#else -template -struct is_convertible_to_wstring_view : std::false_type -{}; -template -struct is_convertible_to_wformat_string : std::false_type -{}; -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT +#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT template -struct is_convertible_to_any_string_view - : std::integral_constant::value || is_convertible_to_wstring_view::value> -{}; -template -struct is_convertible_to_any_format_string - : std::integral_constant::value || is_convertible_to_wformat_string::value> +struct is_convertible_to_any_format_string : std::integral_constant::value || + is_convertible_to_basic_format_string::value> {}; #if defined(SPDLOG_NO_ATOMIC_LEVELS) diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 1d23c5a6..ff3bef58 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -102,10 +102,8 @@ public: log(loc, lvl, string_view_t{msg}); } - // T cannot be statically converted to neither string_view, nor wstring_view and nor format string - template::value && !is_convertible_to_any_format_string::value, int>::type = 0> + // T cannot be statically converted to format string (including string_view) + template::value, int>::type = 0> void log(source_loc loc, level::level_enum lvl, const T &msg) { log(loc, lvl, "{}", msg);