libstdc++: Fix iota_view::size() to avoid overflow
authorJonathan Wakely <jwakely@redhat.com>
Mon, 24 Aug 2020 15:17:04 +0000 (16:17 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 24 Aug 2020 15:17:04 +0000 (16:17 +0100)
commita0e6f05d26d286f5a73007e425b109f0d327e15f
tree5c8365724b55a1260eafcfc34f8905134cf4a57e
parent074436cf8cdd2a9ce75cadd36deb8301f00e55b9
libstdc++: Fix iota_view::size() to avoid overflow

This avoids the overflow that occurs when negating the most negative
value of an integral type.

Also prevent returning signed int when the values have lower rank and
promote to int.

libstdc++-v3/ChangeLog:

* include/std/ranges (ranges::iota_view::size()): Perform all
calculations in the right unsigned types.
* testsuite/std/ranges/iota/size.cc: New test.
libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/iota/size.cc [new file with mode: 0644]