[Boost-bugs] [Boost C++ Libraries] #10399: Breaking change in Boost.Optional

Subject: [Boost-bugs] [Boost C++ Libraries] #10399: Breaking change in Boost.Optional
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-08-26 05:58:04


#10399: Breaking change in Boost.Optional
---------------------------------+------------------------
 Reporter: mikhailberis | Owner: fcacciola
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: optional
  Version: Boost 1.54.0 | Severity: Regression
 Keywords: optional regression |
---------------------------------+------------------------
 Suppose I have the following types:

 {{{#!c++
     struct container {
       boost::optional<uint16_t> optional() const {
         return value_;
       }
      private:
       boost::optional<uint16_t> value_;
     };

     struct value_wrapper {
       value_wrapper(const container& c) : c_(c) {}
       operator uint16_t () { return 1; }
       operator boost::optional<uint16_t>() { return c_.optional(); }
      private:
       const container& c_;
     };
 }}}

 And that I have the following function:

 {{{#!c++
     value_wrapper value(const container& c) {
       return value_wrapper(c);
     }
 }}}

 The following used to work in MSVC 2010:

 {{{#!c++
     container c;
     // leave c.value_ alone.
     boost::optional<uint16_t> some_value =
       value(c);
     assert(!some_value);
 }}}

 Now with Boost 1.56, this breaks because the constructor for
 some_value from a temporary optional is now marked explicit.

 What is the work-around for the previous behavior to be regained? All
 the following changes cause the assertion to fail:

 {{{#!c++
     boost::optional<uint16_t> some_value(value(c));
     assert(!some_value); // some_value's constructor will use the
     uint16_t conversion operator, therefore some_value == 1

     boost::optional<uint16_t> some_value =
     static_cast<boost::optional<uint16_t> >(value(c));
     assert(!some_value); // same problem as above,
                           // the temporary created will favor
                           // the uint16_t conversion operator
 }}}

 Help?

 PS. For better context, see
 https://github.com/cpp-netlib/cpp-
 netlib/blob/0.11-devel/boost/network/protocol/http/algorithms/linearize.hpp#L145

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10399>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC