PR libstdc++/87982 Fix generate_n and fill_n use of _Size parameter
authorJonathan Wakely <jwakely@redhat.com>
Mon, 29 Apr 2019 12:12:43 +0000 (13:12 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 29 Apr 2019 12:12:43 +0000 (13:12 +0100)
commit846541dd15c8390f61d3d3c01626975af79d96be
treeacdd7472ab025aaa6f9568c19f2a8c0e154a506c
parentca0ddb398fb6173eb97c5d70265e79b9ea2bdc9d
PR libstdc++/87982 Fix generate_n and fill_n use of _Size parameter

The standard only requires that _Size can be converted to an integral
type, not that it can be used for arithmetic. Add a new set of
__size_to_integer helper functions to do the conversion (which will be
ambiguous if there is no one conversion that is better than any others).

Also add tests for DR 426 which requires these algorithms and search_n
to handle negative values of n.

PR libstdc++/87982
* include/bits/stl_algo.h (generate_n): Convert _Size parameter to
an integral type.
* include/bits/stl_algobase.h (__size_to_integer): New overloaded
functions to convert a value to an integral type.
(__fill_n_a, __fill_n_a): Assert that __n is already an integral type.
(fill_n): Convert _Size parameter to an integral type.
* testsuite/25_algorithms/fill_n/dr426.cc: New test.
* testsuite/25_algorithms/generate_n/87982.cc: New test.
* testsuite/25_algorithms/generate_n/dr426.cc: New test.

From-SVN: r270646
libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_algo.h
libstdc++-v3/include/bits/stl_algobase.h
libstdc++-v3/testsuite/25_algorithms/fill_n/87982.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/fill_n/87982_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/fill_n/dr426.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/generate_n/87982.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/generate_n/87982_neg.cc [new file with mode: 0644]
libstdc++-v3/testsuite/25_algorithms/generate_n/dr426.cc [new file with mode: 0644]