std::optional defaut constructor

Marc Glisse marc.glisse@inria.fr
Thu Jun 4 07:21:54 GMT 2020


On Thu, 4 Jun 2020, Ville Voutilainen wrote:

> On Thu, 4 Jun 2020 at 03:05, Ville Voutilainen
> <ville.voutilainen@gmail.com> wrote:
>
>>>> "noexcept" is a red herring, what matters is defaulted vs user-provided.
>>>> In one case, we end up zero-initializing the whole buffer, and not in the
>>>> other.
>>>
>>> Yes, I just came to that conclusion. This is value-init, so the
>>> language manages to zero-init the whole-object,
>>> but with the change, it just calls a user-provided constructor.
>>> That'll then merely boil down to value-initializing just the _Empty
>>> part
>>> of the _Storage in _Optional_payload_base. We are in
>>> http://eel.is/c++draft/dcl.init#8.1.2. The change takes us
>>> to http://eel.is/c++draft/dcl.init#8.1.1.
>>
>> Ha, and optional's default constructor isn't even specified to be defaulted.
>
> So the change is correct. Can we test the change somehow?

It passes the testsuite, and libc++ has been doing it this way for years. 
What I feared was some regression where it would yield worse code in some 
cases, or lose some property (not guaranteed by the standard) like 
triviality (to the point of affecting the ABI?), but I couldn't see 
anything like that happening.

(we still have PR86173 causing unnecessary memset in some cases)

-- 
Marc Glisse


More information about the Gcc-patches mailing list