diff options
author | Patrick Palka <ppalka@redhat.com> | 2020-10-28 12:28:08 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2020-10-28 12:28:08 -0400 |
commit | 8572edc828f6d1e7c8243f901fe7c96f62a11a8e (patch) | |
tree | 020338c23c42a54c46c918ece03aa5312379ca65 /libgo/go | |
parent | f4af2dde57992ae0d60a2077f4f0024327b8e6d5 (diff) | |
download | gcc-8572edc828f6d1e7c8243f901fe7c96f62a11a8e.zip gcc-8572edc828f6d1e7c8243f901fe7c96f62a11a8e.tar.gz gcc-8572edc828f6d1e7c8243f901fe7c96f62a11a8e.tar.bz2 |
libstdc++: Fix arithmetic bug in year_month_weekday conversion [PR96713]
The conversion function year_month_weekday::operator sys_days computes
the offset in days from the first weekday of the month with:
days{(index()-1)*7}
^~~~~~~~~~~~~ type 'unsigned'
We want the above to yield -7d when index() is 0u, but our 'days' alias
is based on long instead of int, so the conversion from unsigned to the
underlying type of 'days' instead yields a large positive value.
This patch fixes this by casting the result of index() to int so that
the initializer is sign-extended in the conversion to long.
The added testcase also verifies we do the right thing when index() == 5.
libstdc++-v3/ChangeLog:
PR libstdc++/96713
* include/std/chrono (year_month_weekday::operator sys_days):
Cast the result of index() to int so that the initializer for
days{} is sign-extended when it's converted to the underlying
type.
* testsuite/std/time/year_month_weekday/3.cc: New test.
Diffstat (limited to 'libgo/go')
0 files changed, 0 insertions, 0 deletions