Opened 4 years ago

Closed 3 years ago

#10445 closed Bugs (fixed)

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

Reported by: russell.mcclellan@… Owned by: Fernando Cacciola
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.

Change History (2)

comment:1 Changed 3 years ago by anonymous

Milestone: To Be DeterminedBoost 1.61.0

comment:2 Changed 3 years ago by akrzemi1

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.