[PATCH] libstdc++: Fix the default constructor of ranges::__detail::__box

Jonathan Wakely jwakely@redhat.com
Fri Oct 30 10:33:29 GMT 2020


On 29/10/20 19:48 -0400, Patrick Palka via Libstdc++ wrote:
>On Thu, 29 Oct 2020, Patrick Palka wrote:
>
>> The class template semiregular-box<T> of [range.semi.wrap] is specified
>> to value-initialize the underlying object whenever its type is default-
>> initializable.  Our primary template for __detail::__box respects this
>> requirement, but the recently added partial specialization (for types
>> which are already semiregular) does not.
>>
>> This patch fixes this issue, and additionally makes the in place
>> constructor explicit (as in the primary template).
>>
>> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
>>
>> libstdc++-v3/ChangeLog:
>>
>> 	* include/std/ranges (__detail::__box): For the partial
>> 	specialization for types that are already semiregular,
>> 	make the default constructor value-initialize the underlying
>> 	object instead of default-initializing it.  Make the
>> 	corresponding in place constructor explicit.
>> 	* testsuite/std/ranges/detail/semiregular_box.cc: New test.
>> ---
>>  libstdc++-v3/include/std/ranges               |  4 +--
>>  .../std/ranges/detail/semiregular_box.cc      | 33 +++++++++++++++++++
>>  2 files changed, 35 insertions(+), 2 deletions(-)
>>  create mode 100644 libstdc++-v3/testsuite/std/ranges/detail/semiregular_box.cc
>>
>> diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
>> index df02b03cada..59aac326309 100644
>> --- a/libstdc++-v3/include/std/ranges
>> +++ b/libstdc++-v3/include/std/ranges
>> @@ -141,7 +141,7 @@ namespace ranges
>>        struct __box<_Tp>
>>        {
>>        private:
>> -	[[no_unique_address]] _Tp _M_value;
>> +	[[no_unique_address]] _Tp _M_value = {};
>
>It would be more consistent with the rest of the header to do = _Tp()
>instead:

OK, thanks.



More information about the Gcc-patches mailing list