diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 296ef42c..67f07418 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -123,7 +123,7 @@ struct is_compiled_string : std::is_base_of {}; # define FMT_COMPILE(s) FMT_STRING(s) #endif -#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_NONTYPE_TEMPLATE_ARGS template Str> struct udl_compiled_string : compiled_string { @@ -586,7 +586,7 @@ void print(const S& format_str, const Args&... args) { print(stdout, format_str, args...); } -#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_NONTYPE_TEMPLATE_ARGS inline namespace literals { template constexpr auto operator""_cf() { using char_t = remove_cvref_t; diff --git a/include/fmt/core.h b/include/fmt/core.h index ac829cfa..4b5cace2 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -133,7 +133,7 @@ // Check if exceptions are disabled. #ifndef FMT_EXCEPTIONS # if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \ - FMT_MSC_VERSION && !_HAS_EXCEPTIONS + (FMT_MSC_VERSION && !_HAS_EXCEPTIONS) # define FMT_EXCEPTIONS 0 # else # define FMT_EXCEPTIONS 1 @@ -149,19 +149,13 @@ # define FMT_NORETURN #endif -#if __cplusplus == 201103L || __cplusplus == 201402L -# if defined(__INTEL_COMPILER) || defined(__PGI) -# define FMT_FALLTHROUGH -# elif defined(__clang__) -# define FMT_FALLTHROUGH [[clang::fallthrough]] -# elif FMT_GCC_VERSION >= 700 && \ - (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520) -# define FMT_FALLTHROUGH [[gnu::fallthrough]] -# else -# define FMT_FALLTHROUGH -# endif -#elif FMT_HAS_CPP17_ATTRIBUTE(fallthrough) +#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough) # define FMT_FALLTHROUGH [[fallthrough]] +#elif defined(__clang__) +# define FMT_FALLTHROUGH [[clang::fallthrough]] +#elif FMT_GCC_VERSION >= 700 && \ + (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520) +# define FMT_FALLTHROUGH [[gnu::fallthrough]] #else # define FMT_FALLTHROUGH #endif @@ -196,7 +190,7 @@ # define FMT_UNCHECKED_ITERATOR(It) \ using _Unchecked_type = It // Mark iterator as checked. #else -# define FMT_UNCHECKED_ITERATOR(It) using DummyTypeName = It +# define FMT_UNCHECKED_ITERATOR(It) using unchecked_type = It #endif #ifndef FMT_BEGIN_NAMESPACE @@ -250,9 +244,9 @@ #endif #ifndef FMT_CONSTEVAL -# if ((FMT_GCC_VERSION >= 1000 || FMT_CLANG_VERSION >= 1101) && \ +# if ((FMT_GCC_VERSION >= 1000 || FMT_CLANG_VERSION >= 1101) && \ __cplusplus >= 202002L && !defined(__apple_build_version__)) || \ - (defined(__cpp_consteval) && \ + (defined(__cpp_consteval) && \ (!FMT_MSC_VERSION || _MSC_FULL_VER >= 193030704)) // consteval is broken in MSVC before VS2022 and Apple clang 13. # define FMT_CONSTEVAL consteval @@ -262,13 +256,13 @@ # endif #endif -#ifndef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#ifndef FMT_USE_NONTYPE_TEMPLATE_ARGS # if defined(__cpp_nontype_template_args) && \ ((FMT_GCC_VERSION >= 903 && __cplusplus >= 201709L) || \ __cpp_nontype_template_args >= 201911L) -# define FMT_USE_NONTYPE_TEMPLATE_PARAMETERS 1 +# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 # else -# define FMT_USE_NONTYPE_TEMPLATE_PARAMETERS 0 +# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0 # endif #endif @@ -313,7 +307,7 @@ struct monostate { FMT_BEGIN_DETAIL_NAMESPACE -// Suppress "unused variable" warnings with the method described in +// Suppresses "unused variable" warnings with the method described in // https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/. // (void)var does not work on many Intel compilers. template FMT_CONSTEXPR void ignore_unused(const T&...) {} @@ -328,7 +322,7 @@ constexpr FMT_INLINE auto is_constant_evaluated( #endif } -// A function to suppress "conditional expression is constant" warnings. +// Suppresses "conditional expression is constant" warnings. template constexpr FMT_INLINE auto const_check(T value) -> T { return value; } @@ -338,7 +332,7 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line, #ifndef FMT_ASSERT # ifdef NDEBUG -// FMT_ASSERT is not empty to avoid -Werror=empty-body. +// FMT_ASSERT is not empty to avoid -Wempty-body. # define FMT_ASSERT(condition, message) \ ::fmt::detail::ignore_unused((condition), (message)) # else @@ -389,8 +383,7 @@ FMT_CONSTEXPR auto to_unsigned(Int value) -> FMT_MSC_WARNING(suppress : 4566) constexpr unsigned char micro[] = "\u00B5"; constexpr auto is_utf8() -> bool { - // Avoid buggy sign extensions in MSVC's constant evaluation mode. - // https://developercommunity.visualstudio.com/t/C-difference-in-behavior-for-unsigned/1233612 + // Avoid buggy sign extensions in MSVC's constant evaluation mode (#2297). using uchar = unsigned char; return FMT_UNICODE || (sizeof(micro) == 3 && uchar(micro[0]) == 0xC2 && uchar(micro[1]) == 0xB5); @@ -2855,7 +2848,7 @@ template class specs_checker : public Handler { constexpr int invalid_arg_index = -1; -#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_NONTYPE_TEMPLATE_ARGS template constexpr auto get_arg_index_by_name(basic_string_view name) -> int { if constexpr (detail::is_statically_named_arg()) { @@ -2870,7 +2863,7 @@ constexpr auto get_arg_index_by_name(basic_string_view name) -> int { template FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view name) -> int { -#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_NONTYPE_TEMPLATE_ARGS if constexpr (sizeof...(Args) > 0) return get_arg_index_by_name<0, Args...>(name); #endif @@ -2903,7 +2896,7 @@ class format_string_checker { return context_.check_arg_id(id), id; } FMT_CONSTEXPR auto on_arg_id(basic_string_view id) -> int { -#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_NONTYPE_TEMPLATE_ARGS auto index = get_arg_index_by_name(id); if (index == invalid_arg_index) on_error("named argument is not found"); return context_.check_arg_id(index), index; diff --git a/include/fmt/format.h b/include/fmt/format.h index 9d037cfe..27285ad0 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -948,7 +948,7 @@ class FMT_API format_error : public std::runtime_error { }; namespace detail_exported { -#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_NONTYPE_TEMPLATE_ARGS template struct fixed_string { constexpr fixed_string(const Char (&str)[N]) { detail::copy_str(static_cast(str), @@ -3532,7 +3532,7 @@ template struct udl_formatter { } }; -# if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +# if FMT_USE_NONTYPE_TEMPLATE_ARGS template Str> struct statically_named_arg : view { @@ -4148,7 +4148,7 @@ inline namespace literals { fmt::print("Elapsed time: {s:.2f} seconds", "s"_a=1.23); \endrst */ -# if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +# if FMT_USE_NONTYPE_TEMPLATE_ARGS template constexpr auto operator""_a() { using char_t = remove_cvref_t; return detail::udl_arg(); diff --git a/include/fmt/xchar.h b/include/fmt/xchar.h index 4e9e723a..6e3e76de 100644 --- a/include/fmt/xchar.h +++ b/include/fmt/xchar.h @@ -52,7 +52,7 @@ constexpr auto operator"" _format(const wchar_t* s, size_t n) return {{s, n}}; } -#if FMT_USE_USER_DEFINED_LITERALS && !FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_USER_DEFINED_LITERALS && !FMT_USE_NONTYPE_TEMPLATE_ARGS constexpr detail::udl_arg operator"" _a(const wchar_t* s, size_t) { return {s}; } diff --git a/test/compile-error-test/CMakeLists.txt b/test/compile-error-test/CMakeLists.txt index a960e86d..9c65dfdc 100644 --- a/test/compile-error-test/CMakeLists.txt +++ b/test/compile-error-test/CMakeLists.txt @@ -222,13 +222,13 @@ if (CMAKE_CXX_STANDARD GREATER_EQUAL 20) # Compile-time argument name check expect_compile(format-string-name " - #if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_PARAMETERS + #if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_ARGS using namespace fmt::literals; fmt::print(\"{foo}\", \"foo\"_a=42); #endif ") expect_compile(format-string-name-error " - #if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_PARAMETERS + #if defined(FMT_HAS_CONSTEVAL) && FMT_USE_NONTYPE_TEMPLATE_ARGS using namespace fmt::literals; fmt::print(\"{foo}\", \"bar\"_a=42); #else diff --git a/test/compile-test.cc b/test/compile-test.cc index 2c156847..1337cf4f 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -187,7 +187,7 @@ TEST(compile_test, named) { EXPECT_THROW(fmt::format(FMT_COMPILE("{invalid}"), fmt::arg("valid", 42)), fmt::format_error); -# if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +# if FMT_USE_NONTYPE_TEMPLATE_ARGS using namespace fmt::literals; auto statically_named_field_compiled = fmt::detail::compile(FMT_COMPILE("{arg}")); @@ -285,7 +285,7 @@ TEST(compile_test, print) { } #endif -#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_NONTYPE_TEMPLATE_ARGS TEST(compile_test, compile_format_string_literal) { using namespace fmt::literals; EXPECT_EQ("", fmt::format(""_cf)); diff --git a/test/format-test.cc b/test/format-test.cc index 8e44be13..d32a2491 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1837,7 +1837,7 @@ TEST(format_test, compile_time_string) { EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42)); EXPECT_EQ("foo", fmt::format(FMT_STRING("{}"), string_like())); -#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#if FMT_USE_NONTYPE_TEMPLATE_ARGS using namespace fmt::literals; EXPECT_EQ("foobar", fmt::format(FMT_STRING("{foo}{bar}"), "bar"_a = "bar", "foo"_a = "foo")); @@ -2182,7 +2182,7 @@ TEST(format_test, format_string_errors) { # else fmt::print("warning: constexpr is broken in this version of MSVC\n"); # endif -# if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +# if FMT_USE_NONTYPE_TEMPLATE_ARGS using namespace fmt::literals; EXPECT_ERROR("{foo}", "named argument is not found", decltype("bar"_a = 42)); EXPECT_ERROR("{foo}", "named argument is not found",