[webkit-dev] Watch out for std::optional's move constructor

Chris Dumez cdumez at apple.com
Sun Dec 16 20:37:51 PST 2018


> On Dec 16, 2018, at 7:43 PM, Fujii Hironori <fujii.hironori at gmail.com> wrote:
> 
> I don't like the proposal because it encourages misuse of move.
> We can use move only for values about to be destroyed.

Just for reference, there are close to 400 matches for "WTFMove(m_” in our code base. People do seem to rely on the state of objects after being moved out.
I totally agree that the state of the object being moved out is not defined by the C++ standard. However, so far, in WebKit, we’ve been careful with our move-constructors.

I think that if we do not update std::optional’s move constructor, then I worry we’ll keep having to fix bugs in the future due to its misuse. Although, maybe this mail thread will help.

That being said, I agree with your and Daniel and we should use std::exchange more. I think all the "WTFMove(m_” lines in our code bases should probably be replaced with std::exchange.


> 
> I like Dan's suggestion. We should use std::exchange or std::optional::swap for the cases.
> Or, what about adding a new method WTF::Optional::release() for the case?
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev



More information about the webkit-dev mailing list