optional-bare icon indicating copy to clipboard operation
optional-bare copied to clipboard

Exception thrown in copy constructor when copying empty optional

Open Andoku opened this issue 3 years ago • 3 comments

https://github.com/martinmoene/optional-bare/blob/0bb1d183bcee1e854c4ea196b533252c51f98b81/include/nonstd/optional.hpp#L179

May be I don't understand something, but how this line is supposed to work if method value() always checks assert(has_value())? As i understand it we will always get exception when trying to copy empty optional.

Andoku avatar Feb 26 '21 23:02 Andoku

Thanks @Andoku , for spotting & reporting this.

Added the missing test case and corrected the behaviour.

martinmoene avatar Feb 27 '21 08:02 martinmoene

@martinmoene I think assignment operator has the same problem

Andoku avatar Feb 27 '21 09:02 Andoku

Ah thanks,will look at that too.

martinmoene avatar Feb 27 '21 09:02 martinmoene