[PATCH 4/4] libstdc++: Remove cv-qualifiers from type of std::optional's contained value
Jonathan Wakely
jwakely@redhat.com
Thu Nov 20 18:54:52 GMT 2025
On Thu, 20 Nov 2025 at 18:51, Tomasz Kaminski <tkaminsk@redhat.com> wrote:
>
>
>
> On Thu, Nov 20, 2025 at 6:03 PM Jonathan Wakely <jwakely@redhat.com> wrote:
>>
>> I think this was the only part of the recently-approved LWG 4015 changes
>> which affect our implementation, because we already store the value as a
>> union member, and already have accessors for that value which are not
>> prone to the ADL problems solved by changes like replacing *rhs with
>> rhs.operator*().
>>
>> libstdc++-v3/ChangeLog:
>>
>> * include/std/optional (_Storage::_M_value): Use remove_cv_t for
>> type of union member.
>> ---
>>
>> Tested x86_64-linux.
>>
>> libstdc++-v3/include/std/optional | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
>> index 39db8d3d4a0f..0f718a22cf18 100644
>> --- a/libstdc++-v3/include/std/optional
>> +++ b/libstdc++-v3/include/std/optional
>> @@ -249,7 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> #endif
>>
>> _Empty_byte _M_empty;
>> - _Up _M_value;
>> + remove_cv_t<_Up> _M_value;
>
> This changes are already done inside _Storage class template, with template
> parameter _Up, and we instantiate it with _Storage<_Stored_type> where
> using _Stored_type = remove_const_t<_Tp>;
> So I do not think this is changing anything, and if so would just be confusing.
Oops, yes! I thought I remembered us already implementing this but I
looked at the file briefly and didn't see any use of remove_cv ...
because we used remove_const instead (and it's even present in
experimental::optional).
Patch withdrawn - thanks.
>
>> };
>>
>> #if __cpp_concepts < 202002L
>> @@ -288,7 +288,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>> _Storage& operator=(_Storage&&) = default;
>>
>> _Empty_byte _M_empty;
>> - _Up _M_value;
>> + remove_cv_t<_Up> _M_value;
>> };
>> #endif
>>
>> --
>> 2.51.1
>>
More information about the Libstdc++
mailing list