From 57f394e15678d09c4ccc8d05ba91c49ad1aa494f Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 25 Aug 2018 12:06:57 +0300 Subject: [PATCH] Fix type-safe formatting --- Utilities/Log.h | 3 +-- Utilities/StrFmt.h | 10 ++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Utilities/Log.h b/Utilities/Log.h index 0e34bc4936..3b3efa46eb 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -74,8 +74,7 @@ namespace logs if (UNLIKELY(sev <= enabled)) { static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...}; - const u64 arg_array[sizeof...(Args) + 1]{fmt_unveil::get(args)...}; - message{this, sev}.broadcast(fmt, type_list, arg_array); + message{this, sev}.broadcast(fmt, type_list, fmt_args_t{fmt_unveil::get(args)...}); } } diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 542ee45cea..3d233d1a99 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -244,6 +244,10 @@ struct fmt_type_info } }; +// Argument array type (each element generated via fmt_unveil<>) +template +using fmt_args_t = const u64(&&)[sizeof...(Args) + 1]; + namespace fmt { // Base-57 format helper @@ -286,8 +290,7 @@ namespace fmt SAFE_BUFFERS FORCE_INLINE void append(std::string& out, const char* fmt, const Args&... args) { static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...}; - const u64 arg_array[sizeof...(Args) + 1]{fmt_unveil::get(args)...}; - raw_append(out, fmt, type_list, arg_array); + raw_append(out, fmt, type_list, fmt_args_t{fmt_unveil::get(args)...}); } // Formatting function @@ -308,7 +311,6 @@ namespace fmt [[noreturn]] SAFE_BUFFERS FORCE_INLINE void throw_exception(const char* fmt, const Args&... args) { static constexpr fmt_type_info type_list[sizeof...(Args) + 1]{fmt_type_info::make>()...}; - const u64 arg_array[sizeof...(Args) + 1]{fmt_unveil::get(args)...}; - raw_throw_exception(fmt, type_list, arg_array); + raw_throw_exception(fmt, type_list, fmt_args_t{fmt_unveil::get(args)...}); } }