From 3cc45681c66e7385299cb8bdb0aa5b5123a9524e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kami=C5=84ski?= Date: Fri, 27 Jun 2025 12:35:53 +0200 Subject: libstdc++: Fix warnings introduced by type-erasing for chrono commits [PR110739] The r16-1709-g4b3cefed1a08344495fedec4982d85168bd8173f caused `-Woverflow` in empty_spec.cc file. This warning is not cause by any issue in shipping code, and results in taking to much shortcut when implementing a test-only custom representation type Rep, where long was always used to store a value. In particular common type for Rep and long long int, was de-facto long. This is addressed by adding Under template parameter, that controls the type of stored value, and handling it properly in common_type specializations. No changes to shipping code are necessary. Secondly, extracting _M_locale_fmt calls in r16-1712-gcaac94, resulted in __ctx format parameter no longer being used. This patch removes such parameter entirely, and replace _FormatContext template parameter, with _OutIter parameter for __out. For consistency type of the __out is decoupled from _FormatContext, for functions that still need context: * to extract locale (_M_A_a, _M_B_b, _M_c, _M_p, _M_r, _M_subsecs) * perform formatting for duration/subseconds (_M_Q, _M_T, _M_S, _M_subsecs) PR libstdc++/110739 libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (__formatter_chrono::_M_format_to): Rename _Out to _OutIter for consistency, and update calls to specifier functions. (__formatter_chrono::_M_wi, __formatter_chrono::_M_C_y_Y) (__formatter_chrono::_M_D_x, __formatter_chrono::_M_d_e) (__formatter_chrono::_M_F, __formatter_chrono::_M_g_G) (__formatter_chrono::_M_H_I, __formatter_chrono::_M_j) (__formatter_chrono::_M_m, __formatter_chrono::_M_M) (__formatter_chrono::_M_q, __formatter_chrono::_M_R_X) (__formatter_chrono::_M_u_w, __formatter_chrono::_M_U_V_W) (__formatter_chrono::_M_z, __formatter_chrono::_M_z): Remove _FormatContext parameter, and introduce _OutIter for __out type. (__formatter_chrono::_M_a_A, __formatter_chrono::_M_B_b) (__formatter_chrono::_M_p, __formatter_chrono::_M_Q) (__formatter_chrono::_M_r, __formatter_chrono::_M_S) (__formatter_chrono::_M_subsecs, __formatter_chrono::_M_T): Introduce separate _OutIter template parameter for __out. (__formatter_chrono::_M_c, __formatter_chrono::_M_T): Likewise, and adjust calls to specifiers functions. * testsuite/std/time/format/empty_spec.cc: Make underlying type for Rep configurable. --- .../testsuite/std/time/format/empty_spec.cc | 43 +++++++++++++--------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'libstdc++-v3/testsuite/std') diff --git a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc index 923df3d..ef1b19d 100644 --- a/libstdc++-v3/testsuite/std/time/format/empty_spec.cc +++ b/libstdc++-v3/testsuite/std/time/format/empty_spec.cc @@ -77,15 +77,18 @@ test_padding() VERIFY( res == WIDEN("==16 is not a valid month==") ); } -template +template struct Rep { using Return = std::conditional_t, Rep, Ret>; - Rep(long v = 0) : val(v) {} + Rep(Under v = 0) : val(v) {} - operator long() const + template + Rep(Rep o) : val(o.val) {} + + operator Under() const { return val; } Return @@ -119,37 +122,43 @@ struct Rep operator<<(std::basic_ostream& os, const Rep& t) { return os << t.val << WIDEN("[via <<]"); } - long val; + Under val; +}; + +template +struct std::common_type, Rep> +{ + using type = Rep>; }; -template +template requires std::is_integral_v -struct std::common_type, Other> +struct std::common_type, Other> { - using type = Rep; + using type = Rep>; }; -template +template requires std::is_integral_v -struct std::common_type> - : std::common_type, Other> +struct std::common_type> + : std::common_type, Other> { }; -template -struct std::numeric_limits> - : std::numeric_limits +template +struct std::numeric_limits> + : std::numeric_limits { }; -template -struct std::formatter, CharT> - : std::formatter +template +struct std::formatter, CharT> + : std::formatter { template typename std::basic_format_context::iterator format(const Rep& t, std::basic_format_context& ctx) const { constexpr std::basic_string_view suffix = WIDEN("[via format]"); - auto out = std::formatter::format(t.val, ctx); + auto out = std::formatter::format(t.val, ctx); return std::ranges::copy(suffix, out).out; } }; -- cgit v1.1