From f5a16a484bdf072959dc27ea18dc0ec534eee251 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 6 Sep 2024 12:27:48 -0700 Subject: [PATCH] Cleanup --- include/fmt/args.h | 19 ++++--------- include/fmt/format.h | 21 ++++++-------- include/fmt/os.h | 4 +-- include/fmt/xchar.h | 2 +- .../mkdocstrings_handlers/cxx/__init__.py | 2 +- test/compile-error-test/CMakeLists.txt | 28 +------------------ test/format-test.cc | 4 +-- test/xchar-test.cc | 4 +-- 8 files changed, 24 insertions(+), 60 deletions(-) diff --git a/include/fmt/args.h b/include/fmt/args.h index d84d840f..287856c9 100644 --- a/include/fmt/args.h +++ b/include/fmt/args.h @@ -73,12 +73,7 @@ class dynamic_arg_list { * into type-erased formatting functions such as `fmt::vformat`. */ template -class dynamic_format_arg_store -#if FMT_GCC_VERSION && FMT_GCC_VERSION < 409 - // Workaround a GCC template argument substitution bug. - : public basic_format_args -#endif -{ +class dynamic_format_arg_store { private: using char_type = typename Context::char_type; @@ -97,7 +92,7 @@ class dynamic_format_arg_store }; template - using stored_type = conditional_t< + using stored_t = conditional_t< std::is_convertible>::value && !detail::is_reference_wrapper::value, std::basic_string, T>; @@ -122,10 +117,8 @@ class dynamic_format_arg_store template void emplace_arg(const detail::named_arg& arg) { - if (named_info_.empty()) { - constexpr const detail::named_arg_info* zero_ptr{nullptr}; - data_.insert(data_.begin(), basic_format_arg(zero_ptr, 0)); - } + if (named_info_.empty()) + data_.insert(data_.begin(), basic_format_arg(nullptr, 0)); data_.emplace_back(detail::make_arg(detail::unwrap(arg.value))); auto pop_one = [](std::vector>* data) { data->pop_back(); @@ -162,7 +155,7 @@ class dynamic_format_arg_store */ template void push_back(const T& arg) { if (detail::const_check(need_copy::value)) - emplace_arg(dynamic_args_.push>(arg)); + emplace_arg(dynamic_args_.push>(arg)); else emplace_arg(detail::unwrap(arg)); } @@ -198,7 +191,7 @@ class dynamic_format_arg_store dynamic_args_.push>(arg.name).c_str(); if (detail::const_check(need_copy::value)) { emplace_arg( - fmt::arg(arg_name, dynamic_args_.push>(arg.value))); + fmt::arg(arg_name, dynamic_args_.push>(arg.value))); } else { emplace_arg(fmt::arg(arg_name, arg.value)); } diff --git a/include/fmt/format.h b/include/fmt/format.h index f9f6c457..e46c9168 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -140,17 +140,14 @@ FMT_END_NAMESPACE # endif #endif -#ifndef FMT_USE_USER_DEFINED_LITERALS +#ifndef FMT_USE_USER_LITERALS // EDG based compilers (Intel, NVIDIA, Elbrus, etc), GCC and MSVC support UDLs. -// -// GCC before 4.9 requires a space in `operator"" _a` which is invalid in later -// compiler versions. -# if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION >= 409 || \ +# if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION || \ FMT_MSC_VERSION >= 1900) && \ (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= /* UDL feature */ 480) -# define FMT_USE_USER_DEFINED_LITERALS 1 +# define FMT_USE_USER_LITERALS 1 # else -# define FMT_USE_USER_DEFINED_LITERALS 0 +# define FMT_USE_USER_LITERALS 0 # endif #endif @@ -3775,7 +3772,7 @@ FMT_CONSTEXPR void handle_dynamic_spec( if (kind != arg_id_kind::none) value = get_dynamic_spec(kind, ref, ctx); } -#if FMT_USE_USER_DEFINED_LITERALS +#if FMT_USE_USER_LITERALS # if FMT_USE_NONTYPE_TEMPLATE_ARGS template Str> @@ -3810,8 +3807,8 @@ template struct udl_arg { return {str, std::forward(value)}; } }; -# endif -#endif // FMT_USE_USER_DEFINED_LITERALS +# endif // FMT_USE_NONTYPE_TEMPLATE_ARGS +#endif // FMT_USE_USER_LITERALS template struct format_handler { parse_context parse_ctx; @@ -4294,7 +4291,7 @@ struct formatter : detail::native_formatter {}; -#if FMT_USE_USER_DEFINED_LITERALS +#if FMT_USE_USER_LITERALS inline namespace literals { /** * User-defined literal equivalent of `fmt::arg`. @@ -4315,7 +4312,7 @@ constexpr auto operator""_a(const char* s, size_t) -> detail::udl_arg { } # endif } // namespace literals -#endif // FMT_USE_USER_DEFINED_LITERALS +#endif // FMT_USE_USER_LITERALS FMT_API auto vformat(string_view fmt, format_args args) -> std::string; diff --git a/include/fmt/os.h b/include/fmt/os.h index 4158b844..91afeee8 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -147,8 +147,8 @@ FMT_API std::system_error vwindows_error(int error_code, string_view format_str, * } */ template -std::system_error windows_error(int error_code, string_view message, - const T&... args) { +auto windows_error(int error_code, string_view message, + const T&... args) -> std::system_error { return vwindows_error(error_code, message, vargs{{args...}}); } diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 0fb95244..1ffaf11b 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -89,7 +89,7 @@ constexpr auto make_wformat_args(T&... args) } inline namespace literals { -#if FMT_USE_USER_DEFINED_LITERALS && !FMT_USE_NONTYPE_TEMPLATE_ARGS +#if FMT_USE_USER_LITERALS && !FMT_USE_NONTYPE_TEMPLATE_ARGS constexpr auto operator""_a(const wchar_t* s, size_t) -> detail::udl_arg { return {s}; diff --git a/support/python/mkdocstrings_handlers/cxx/__init__.py b/support/python/mkdocstrings_handlers/cxx/__init__.py index 21dce201..85d52a58 100644 --- a/support/python/mkdocstrings_handlers/cxx/__init__.py +++ b/support/python/mkdocstrings_handlers/cxx/__init__.py @@ -198,7 +198,7 @@ class CxxHandler(BaseHandler): PREDEFINED = _WIN32=1 \ __linux__=1 \ FMT_ENABLE_IF(...)= \ - FMT_USE_USER_DEFINED_LITERALS=1 \ + FMT_USE_USER_LITERALS=1 \ FMT_USE_ALIAS_TEMPLATES=1 \ FMT_USE_NONTYPE_TEMPLATE_ARGS=1 \ FMT_API= \ diff --git a/test/compile-error-test/CMakeLists.txt b/test/compile-error-test/CMakeLists.txt index c4a16068..a86996e2 100644 --- a/test/compile-error-test/CMakeLists.txt +++ b/test/compile-error-test/CMakeLists.txt @@ -115,8 +115,7 @@ function (run_tests) endif () endfunction () - -# check if the source file skeleton compiles +# Check if the source file skeleton compiles. expect_compile(check "") expect_compile(check-error "compilation_error" ERROR) @@ -166,31 +165,6 @@ expect_compile(format-lots-of-arguments-with-function " fmt::format(\"\", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, f); " ERROR) -# Check if user-defined literals are available -include(CheckCXXSourceCompiles) -set(CMAKE_REQUIRED_FLAGS ${CXX_STANDARD_FLAG}) -check_cxx_source_compiles(" - void operator\"\" _udl(long double); - int main() {}" - SUPPORTS_USER_DEFINED_LITERALS) -set(CMAKE_REQUIRED_FLAGS ) -if (NOT SUPPORTS_USER_DEFINED_LITERALS) - set (SUPPORTS_USER_DEFINED_LITERALS OFF) -endif () - -# Make sure that compiler features detected in the header -# match the features detected in CMake. -if (SUPPORTS_USER_DEFINED_LITERALS) - set(supports_udl 1) -else () - set(supports_udl 0) -endif () -expect_compile(udl-check " - #if FMT_USE_USER_DEFINED_LITERALS != ${supports_udl} - # error - #endif -") - if (CMAKE_CXX_STANDARD GREATER_EQUAL 20) # Compile-time argument type check expect_compile(format-string-number-spec " diff --git a/test/format-test.cc b/test/format-test.cc index 1fe575ab..a5f91b8c 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2005,7 +2005,7 @@ TEST(format_test, custom_format_compile_time_string) { EXPECT_EQ(fmt::format(FMT_STRING("{}"), const_answer), "42"); } -#if FMT_USE_USER_DEFINED_LITERALS +#if FMT_USE_USER_LITERALS TEST(format_test, named_arg_udl) { using namespace fmt::literals; auto udl_a = fmt::format("{first}{second}{first}{third}", "first"_a = "abra", @@ -2017,7 +2017,7 @@ TEST(format_test, named_arg_udl) { EXPECT_EQ(fmt::format("{answer}", "answer"_a = Answer()), "42"); } -#endif // FMT_USE_USER_DEFINED_LITERALS +#endif // FMT_USE_USER_LITERALS TEST(format_test, enum) { EXPECT_EQ(fmt::format("{}", foo), "0"); } diff --git a/test/xchar-test.cc b/test/xchar-test.cc index d3e5f558..83b451d4 100644 --- a/test/xchar-test.cc +++ b/test/xchar-test.cc @@ -231,7 +231,7 @@ TEST(format_test, wide_format_to_n) { EXPECT_EQ(L"BC x", fmt::wstring_view(buffer, 4)); } -#if FMT_USE_USER_DEFINED_LITERALS +#if FMT_USE_USER_LITERALS TEST(xchar_test, named_arg_udl) { using namespace fmt::literals; auto udl_a = @@ -242,7 +242,7 @@ TEST(xchar_test, named_arg_udl) { fmt::arg(L"second", L"cad"), fmt::arg(L"third", 99)), udl_a); } -#endif // FMT_USE_USER_DEFINED_LITERALS +#endif // FMT_USE_USER_LITERALS TEST(xchar_test, print) { // Check that the wide print overload compiles.