diff options
author | Patrick Palka <ppalka@redhat.com> | 2020-08-27 14:11:24 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2020-08-27 14:11:24 -0400 |
commit | 71e9716137d47872f30f933ff99ba9ef3df1665c (patch) | |
tree | 56ed98ef11b7279b60c08c1d43d45fe837f3d368 /libstdc++-v3/include/std/chrono | |
parent | 7b743c67f04471a0129390ad2808e61e5538e0d3 (diff) | |
download | gcc-71e9716137d47872f30f933ff99ba9ef3df1665c.zip gcc-71e9716137d47872f30f933ff99ba9ef3df1665c.tar.gz gcc-71e9716137d47872f30f933ff99ba9ef3df1665c.tar.bz2 |
libstdc++: Fix arithmetic bug in chrono::year_month::operator+
This fixes the months-based addition for year_month when the
year_month's month component is 0.
libstdc++-v3/ChangeLog:
* include/std/chrono (year_month::operator+): Properly handle a
month value of 0 by casting the month value to int before
subtracting 1 from it so that the difference is sign-extended in
the subsequent addition.
* testsuite/std/time/year_month/1.cc: Test adding months to a
year_month whose month component is below or above the
normalized range of [1,12].
Diffstat (limited to 'libstdc++-v3/include/std/chrono')
-rw-r--r-- | libstdc++-v3/include/std/chrono | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index df2f5d2..9fc8f56 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -2133,7 +2133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { // TODO: Optimize? auto __m = __ym.month() + __dm; - auto __i = unsigned{__ym.month()} - 1 + __dm.count(); + auto __i = int(unsigned(__ym.month())) - 1 + __dm.count(); auto __y = (__i < 0 ? __ym.year() + years{(__i - 11) / 12} : __ym.year() + years{__i / 12}); |