gcc/libstdc++-v3/testsuite/std
Jonathan Wakely 344f413220 libstdc++: Fix formatting of negative chrono::hh_mm_ss
When formatting with an empty chrono spec ("{}") two minus signs were
being added to hh_mm_ss values. This is because the __is_neg flag was
checked to add one explicitly, and then the ostream operator added
another one.

We should only check the __is_neg flag for durations, because those are
the only types which are modified to be non-negative before calling
_M_format. We don't change hh_mm_ss values to be negative, because that
would require performing arithmetic on the hh_mm_ss members to sum them,
and then again to construct a new hh_mm_ss object with the positive
value.  Instead, we can just be careful about using the __is_neg flag
correctly.

To fix the bug, _M_format_to_ostream no longer checks the __is_neg flag
for non-durations, and _M_format doesn't set it for hh_mm_ss until after
the call to _M_format_to_ostream. We can also avoid setting it for types
that it doesn't apply to, by making the __print_sign lambda only inspect
it for duration and hh_mm_ss types.

libstdc++-v3/ChangeLog:

	* include/bits/chrono_io.h (__formatter_chrono::_M_format):
	Do not set __is_neg for hh_mm_ss before calling
	_M_format_to_ostream. Change __print_sign lambda to only check
	__is_neg for durations and hh_mm_ss types.
	(__formatter_chrono::_M_format_to_ostream): Only check __is_neg
	for duration types.
	* testsuite/std/time/hh_mm_ss/io.cc: Check negative values.
2023-07-19 16:48:56 +01:00
..
concepts Update copyright years. 2023-01-16 11:52:17 +01:00
format libstdc++: Fix std::format for pointers [PR110239] 2023-06-26 17:43:22 +01:00
ranges libstdc++: Fix __max_diff_type::operator>>= for negative values 2023-04-24 13:39:54 -04:00
time libstdc++: Fix formatting of negative chrono::hh_mm_ss 2023-07-19 16:48:56 +01:00