STL icon indicating copy to clipboard operation
STL copied to clipboard

LWG-4015 LWG-3973 broke `const` overloads of `std::optional` monadic operations

Open StephanTLavavej opened this issue 1 month ago • 2 comments

LWG-4015 LWG-3973 broke const overloads of std::optional monadic operations

It looks like this may be unobservable for us right now, especially because in #4158 I noted that the earlier LWG-3973 was "Implemented without comments". However, I do observe variation between our current implementation and LWG-4015's resolution. For example, our converting move constructor says _STD move(*_Right) (i.e. deref optional, then move):

https://github.com/microsoft/STL/blob/ab6dec6d85c90b272d219ba60da4478b169b72b4/stl/inc/optional#L292-L296

But LWG-4015 specifies std::move(rhs).operator*(), i.e. move optional, then deref.

I'll note this issue in #5607 tracking optional<T&>, but I think we can clean up divergence here before implementing that feature.

StephanTLavavej avatar Nov 14 '25 17:11 StephanTLavavej

Hi, I'd like to work on this issue.

khaledS20 avatar Nov 19 '25 16:11 khaledS20

Just do it. You can test this with ADL-found operator* like, e.g.

namespace bad {
    template<class T>
    void operator*(const optional<T>&) = delete;

    struct S { /* ... */ };
} // namespace bad

// testing optional<bad::S>

frederick-vs-ja avatar Nov 19 '25 18:11 frederick-vs-ja

Hi @khaledS20, do you still plan to address this issue in the near future? It has been three weeks since the last activity. If not, I will handle the issue the following week.

vmichal avatar Dec 08 '25 23:12 vmichal