Opened 6 years ago

Closed 6 years ago

#12652 closed Bugs (fixed)

boost::optional<DefaultConstructable>::operator= chooses wrong overload for {}

Reported by: mathias@… Owned by: Fernando Cacciola
Milestone: Boost 1.63.0 Component: optional
Version: Boost 1.63.0 Severity: Problem
Keywords: Cc:

Description

boost::optional<int> op = 5; // creates engaged optional
op = {}; // currently does op = 0;

For most types operator={} assigns from a value-constructed value of that type. That is the behavior of std::experimental::optional but not boost::optional<T>. It chooses the T&& overload. I think the standard avoids it by having the assign-from-T operator= be templated on U instead, which doesn't match {}.

Attachments (1)

test.cpp (266 bytes ) - added by mathias@… 6 years ago.
Shows the issue. (Compiled with g++6.2 with no extra args)

Download all attachments as: .zip

Change History (2)

by mathias@…, 6 years ago

Attachment: test.cpp added

Shows the issue. (Compiled with g++6.2 with no extra args)

comment:1 by akrzemi1, 6 years ago

Milestone: To Be DeterminedBoost 1.63.0
Resolution: fixed
Status: newclosed
Version: Boost 1.61.0Boost 1.63.0

Already fixed in 1.63

Note: See TracTickets for help on using tickets.