[PATCH] libstdc++: Fix incorrect use of memset in ranges::fill_n (PR 94017)
Jonathan Wakely
jwakely@redhat.com
Tue Mar 3 22:33:00 GMT 2020
On 03/03/20 17:13 -0500, Patrick Palka wrote:
>On Tue, 3 Mar 2020, Patrick Palka wrote:
>
>> When deciding whether to perform the memset optimization in ranges::fill_n, we
>> were crucially neglecting to check whether the output pointer's value type is a
>> byte type. This patch adds such a check to the problematic condition in
>> ranges::fill_n.
>>
>> I think the __is_byte<_Tp>::__value check, which checks that the fill type is a
>> byte type, is too restrictive. It means that we won't enable the memset
>> optimization in the following example:
>>
>> char c[100];
>> ranges::fill(c, 37);
>>
>> since the fill type is deduced to be int here. It seems we could get away
>> with instead just checking that _Tp is an integral type; I've added a TODO
>> about this in the code.
>
>Here's v2 of the patch which actually replaces the aforementioned
>conservative condition with integral<_Tp>, following discussion on IRC.
OK for master, thanks.
More information about the Libstdc++
mailing list