ptal / expected

What did you expect?
113 stars 18 forks source link

[GCC] invalid initialization of non-const reference of type 'int&' #80

Closed hrobeers closed 9 years ago

hrobeers commented 9 years ago

GCC comiple error when using int as unexpected type.

error: invalid initialization of non-const reference of type 'int&' from an rvalue of type 'std::remove_reference<int&>::type {aka int}'
       return constexpr_move(error_);

commenting out:

    BOOST_EXPECTED_CONSTEXPR_IF_MOVE_ACCESSORS
    BOOST_FORCEINLINE ErrorType& value() &&
    {
      return constexpr_move(error_);
    }

in unexpected.hpp fixes the issue, but is not optimal.

viboes commented 9 years ago

What I see in the repository line 1006 is

  BOOST_EXPECTED_CONSTEXPR_IF_MOVE_ACCESSORS value_type&& value() &&
  {
    if (!valid()) error::rethrow<error_type>(contained_err());
    return std::move(contained_val());
  }

``
hrobeers commented 9 years ago

Hi viboes,

The following piece of code triggers the compilation error on line 54 of unexpected.hpp:

#include <string>
#include "boost/expected/expected.hpp"

using namespace std;
using namespace boost;

int main()
{
    expected<string, int> exp = make_unexpected(5);

    if (!exp)
        return exp.get_unexpected().value();

    return 0;
}
viboes commented 9 years ago

Please, could you update with

https://github.com/ptal/expected/commit/d79715f84e5223ca5ee7fb6a6d1b068204e0e350

hrobeers commented 9 years ago

Thanks for the fast reaction. Issue is fixed!

viboes commented 9 years ago

Thanks to you for catching this error.