From ff6e46ed972a3b9c0b5f37d0e3c44257d9646150 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 22 Sep 2018 16:00:34 -0700 Subject: [PATCH] More cleanup --- include/fmt/core.h | 52 +++++++++++++++------------------------- include/fmt/format.h | 22 ++++++++--------- test/format-impl-test.cc | 6 +++++ 3 files changed, 36 insertions(+), 44 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 3ec08c7b..3f84d5a1 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -25,7 +25,7 @@ #endif #if defined(__has_include) && !defined(__INTELLISENSE__) && \ - (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1600) + !(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1600) # define FMT_HAS_INCLUDE(x) __has_include(x) #else # define FMT_HAS_INCLUDE(x) 0 @@ -72,7 +72,7 @@ #ifndef FMT_USE_CONSTEXPR11 # define FMT_USE_CONSTEXPR11 \ - (FMT_MSC_VER >= 1900 || FMT_GCC_VERSION >= 406 || FMT_USE_CONSTEXPR) + (FMT_USE_CONSTEXPR || FMT_GCC_VERSION >= 406 || FMT_MSC_VER >= 1900) #endif #if FMT_USE_CONSTEXPR11 # define FMT_CONSTEXPR11 constexpr @@ -104,24 +104,15 @@ # define FMT_NULL NULL # endif #endif - #ifndef FMT_USE_NULLPTR # define FMT_USE_NULLPTR 0 #endif -#if FMT_HAS_CPP_ATTRIBUTE(noreturn) -# define FMT_NORETURN [[noreturn]] -#else -# define FMT_NORETURN -#endif - // Check if exceptions are disabled. -#if defined(__GNUC__) && !defined(__EXCEPTIONS) +#if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \ + FMT_MSC_VER && !_HAS_EXCEPTIONS # define FMT_EXCEPTIONS 0 -#elif FMT_MSC_VER && !_HAS_EXCEPTIONS -# define FMT_EXCEPTIONS 0 -#endif -#ifndef FMT_EXCEPTIONS +#else # define FMT_EXCEPTIONS 1 #endif @@ -147,8 +138,7 @@ # endif #endif -// This is needed because GCC still uses throw() in its headers when exceptions -// are disabled. +// GCC still uses throw() in its headers when exceptions are disabled. #if FMT_GCC_VERSION # define FMT_DTOR_NOEXCEPT FMT_DETECTED_NOEXCEPT #else @@ -358,11 +348,8 @@ struct formatter { }; template -struct convert_to_int { - enum { - value = !std::is_arithmetic::value && std::is_convertible::value - }; -}; +struct convert_to_int: std::integral_constant< + bool, !std::is_arithmetic::value && std::is_convertible::value> {}; namespace internal { @@ -1115,13 +1102,13 @@ const long long format_arg_store::TYPES = get_types(); */ template inline format_arg_store - make_format_args(const Args & ... args) { + make_format_args(const Args &... args) { return format_arg_store(args...); } template inline format_arg_store - make_format_args(const Args & ... args) { + make_format_args(const Args &... args) { return format_arg_store(args...); } @@ -1222,12 +1209,12 @@ class basic_format_args { // It is a separate type rather than a typedef to make symbols readable. struct format_args: basic_format_args { template - format_args(Args && ... arg) + format_args(Args &&... arg) : basic_format_args(std::forward(arg)...) {} }; struct wformat_args : basic_format_args { template - wformat_args(Args && ... arg) + wformat_args(Args &&... arg) : basic_format_args(std::forward(arg)...) {} }; @@ -1383,7 +1370,7 @@ template inline typename std::enable_if< is_contiguous::value, std::back_insert_iterator>::type format_to(std::back_insert_iterator out, - string_view format_str, const Args & ... args) { + string_view format_str, const Args &... args) { format_arg_store as{args...}; return vformat_to(out, format_str, as); } @@ -1392,7 +1379,7 @@ template inline typename std::enable_if< is_contiguous::value, std::back_insert_iterator>::type format_to(std::back_insert_iterator out, - wstring_view format_str, const Args & ... args) { + wstring_view format_str, const Args &... args) { return vformat_to(out, format_str, make_format_args(args...)); } @@ -1420,7 +1407,7 @@ inline std::basic_string vformat( template inline std::basic_string< typename internal::format_string_traits::char_type> - format(const String &format_str, const Args & ... args) { + format(const String &format_str, const Args &... args) { internal::check_format_string(format_str); // This should be just // return vformat(format_str, make_format_args(args...)); @@ -1445,7 +1432,7 @@ FMT_API void vprint(std::FILE *f, wstring_view format_str, wformat_args args); \endrst */ template -inline void print(std::FILE *f, string_view format_str, const Args & ... args) { +inline void print(std::FILE *f, string_view format_str, const Args &... args) { format_arg_store as(args...); vprint(f, format_str, as); } @@ -1454,8 +1441,7 @@ inline void print(std::FILE *f, string_view format_str, const Args & ... args) { set via ``fwide(f, 1)`` or ``_setmode(_fileno(f), _O_U8TEXT)`` on Windows. */ template -inline void print(std::FILE *f, wstring_view format_str, - const Args & ... args) { +inline void print(std::FILE *f, wstring_view format_str, const Args &... args) { format_arg_store as(args...); vprint(f, format_str, as); } @@ -1473,13 +1459,13 @@ FMT_API void vprint(wstring_view format_str, wformat_args args); \endrst */ template -inline void print(string_view format_str, const Args & ... args) { +inline void print(string_view format_str, const Args &... args) { format_arg_store as{args...}; vprint(format_str, as); } template -inline void print(wstring_view format_str, const Args & ... args) { +inline void print(wstring_view format_str, const Args &... args) { format_arg_store as(args...); vprint(format_str, as); } diff --git a/include/fmt/format.h b/include/fmt/format.h index d88b78c1..a98f4568 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2375,7 +2375,7 @@ class system_error : public std::runtime_error { \endrst */ template - system_error(int error_code, string_view message, const Args & ... args) + system_error(int error_code, string_view message, const Args &... args) : std::runtime_error("") { init(error_code, message, make_format_args(args...)); } @@ -2663,7 +2663,7 @@ class basic_writer { void write_double(T value, const format_specs &spec); template void write_double_sprintf(T value, const format_specs &spec, - internal::basic_buffer& buffer); + internal::basic_buffer &buffer); template struct str_writer { @@ -2924,7 +2924,7 @@ template template void basic_writer::write_double_sprintf( T value, const format_specs &spec, - internal::basic_buffer& buffer) { + internal::basic_buffer &buffer) { // Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail. FMT_ASSERT(buffer.capacity() != 0, "empty buffer"); @@ -3008,7 +3008,7 @@ class windows_error : public system_error { \endrst */ template - windows_error(int error_code, string_view message, const Args & ... args) { + windows_error(int error_code, string_view message, const Args &... args) { init(error_code, message, make_format_args(args...)); } }; @@ -3315,7 +3315,7 @@ struct format_handler : internal::error_handler { } iterator on_format_specs(iterator it) { - auto& parse_ctx = context.parse_context(); + auto &parse_ctx = context.parse_context(); parse_ctx.advance_to(pointer_from(it)); if (fmt::visit(internal::custom_formatter(context), arg)) return iterator(parse_ctx); @@ -3461,7 +3461,7 @@ template < typename Char = typename internal::format_string_traits::char_type> inline typename buffer_context::type::iterator format_to( basic_memory_buffer &buf, const String &format_str, - const Args & ... args) { + const Args &... args) { internal::check_format_string(format_str); return vformat_to( buf, basic_string_view(format_str), @@ -3506,7 +3506,7 @@ inline OutputIt vformat_to( */ template inline OutputIt format_to(OutputIt out, string_view format_str, - const Args & ... args) { + const Args &... args) { return vformat_to(out, format_str, make_format_args::type>(args...)); } @@ -3528,7 +3528,7 @@ using format_to_n_args = fmt::basic_format_args>; template inline format_arg_store, Args...> - make_format_to_n_args(const Args & ... args) { + make_format_to_n_args(const Args &... args) { return format_arg_store, Args...>(args...); } @@ -3575,7 +3575,7 @@ inline std::basic_string internal::vformat( template inline typename std::enable_if::value>::type - print(String format_str, const Args & ... args) { + print(String format_str, const Args &... args) { internal::check_format_string(format_str); return vprint(format_str.data(), make_format_args(args...)); } @@ -3586,7 +3586,7 @@ inline typename std::enable_if::value>::type */ template inline std::size_t formatted_size(string_view format_str, - const Args & ... args) { + const Args &... args) { auto it = format_to(internal::counting_iterator(), format_str, args...); return it.count(); } @@ -3614,7 +3614,7 @@ struct udl_formatter { const Char *str; template - auto operator()(Args && ... args) const + auto operator()(Args &&... args) const -> decltype(format(str, std::forward(args)...)) { return format(str, std::forward(args)...); } diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 070c4b27..08092516 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -24,6 +24,12 @@ #undef min #undef max +#if FMT_HAS_CPP_ATTRIBUTE(noreturn) +# define FMT_NORETURN [[noreturn]] +#else +# define FMT_NORETURN +#endif + using fmt::internal::fp; template