Opened 3 years ago

Closed 16 months ago

#10445 closed Bugs (fixed)

rvalue assign from boost::optional<const T&> doesn't work

Reported by: russell.mcclellan@… Owned by: fcacciola
Milestone: Boost 1.61.0 Component: optional
Version: Boost 1.56.0 Severity: Regression
Keywords: Cc:


consider the following code:

#include "boost/optional.hpp"
#include <iostream>

struct a 
    int p;

boost::optional<const a&> bar() {
    static a b;
    b.p = 3;
    return b;

int main(int, char**)
    boost::optional<a> baz;
    baz = bar(); // uh-oh!
    return 0;

My expectation is that the line marked "uh-oh" should compile correctly and invoke a's copy constructor to fill in baz's a. What actually happens is that I get a compile error saying that I can't static cast from const a& to a&& inside the move assignment operator for optional.

Attachments (0)

Change History (2)

comment:1 Changed 16 months ago by anonymous

  • Milestone changed from To Be Determined to Boost 1.61.0

comment:2 Changed 16 months ago by akrzemi1

  • Resolution set to fixed
  • Status changed from new to closed

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain fcacciola.
The resolution will be deleted. Next status will be 'reopened'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.