Can't build GTSAM with Boost 1.56 with C++11

Issue #116 resolved
Chris Beall created an issue

Errors about binding optional lvalue references:

C:\local\boost_1_56_0\boost/optional/optional.hpp(188): error C2338: binding rvalue references to optional lvalue references is disallowed (..\..\gtsam\symbolic\SymbolicFactorGraph.cpp)
3>          C:\local\boost_1_56_0\boost/optional/optional.hpp(777) : see reference to function template instantiation 'void boost::optional_detail::prevent_binding_rvalue_ref_to_optional_lvalue_ref<T,gtsam::Ordering&&>(void)' being compiled
3>          with
3>          [
3>              T=const gtsam::Ordering &
3>          ]
3>          C:\local\boost_1_56_0\boost/optional/optional.hpp(776) : while compiling class template member function 'boost::optional<T>::optional(gtsam::Ordering &&)'
3>          with
3>          [
3>              T=const gtsam::Ordering &
3>          ]
3>          C:\Users\Chris\git\gtsam\gtsam/inference/EliminateableFactorGraph-inst.h(56) : see reference to function template instantiation 'boost::optional<T>::optional(gtsam::Ordering &&)' being compiled
3>          with
3>          [
3>              T=const gtsam::Ordering &
3>          ]
3>          C:\Users\Chris\git\gtsam\gtsam/inference/EliminateableFactorGraph-inst.h(32) : see reference to class template instantiation 'boost::optional<T>' being compiled
3>          with
3>          [
3>              T=const gtsam::Ordering &
3>          ]
3>          C:\Users\Chris\git\gtsam\gtsam/inference/EliminateableFactorGraph-inst.h(32) : while compiling class template member function 'boost::shared_ptr<T> gtsam::EliminateableFactorGraph<FACTORGRAPH>::eliminateSequential(gtsam::EliminateableFactorGraph<FACTORGRAPH>::OptionalOrdering,const boost::function<Signature> &,gtsam::EliminateableFactorGraph<FACTORGRAPH>::OptionalVariableIndex) const'
3>          with
3>          [
3>              T=gtsam::SymbolicBayesNet,
3>              FACTORGRAPH=gtsam::SymbolicFactorGraph,
3>              Signature=std::pair<boost::shared_ptr<gtsam::SymbolicConditional>,boost::shared_ptr<gtsam::SymbolicFactor::This>> (const gtsam::SymbolicFactorGraph &,const gtsam::Ordering &)
3>          ]
3>          C:\Users\Chris\git\gtsam\gtsam/symbolic/SymbolicFactorGraph.h(58) : see reference to class template instantiation 'gtsam::EliminateableFactorGraph<FACTORGRAPH>' being compiled
3>          with
3>          [
3>              FACTORGRAPH=gtsam::SymbolicFactorGraph
3>          ]

Comments (12)

  1. Andrew Melim

    This is a boost assertion being thrown due to the following

    "Rvalue references and lvalue references to const have the ability in C++ to extend the life time of a temporary they bind to. Optional references do not have this capability, therefore to avoid surprising effects it is not possible to initialize an optional references from a temporary. Optional rvalue references are disabled altogether. Also, the initialization and assignment of an optional reference to const from rvalue reference is disabled."

    http://www.boost.org/doc/libs/1_56_0/libs/optional/doc/html/boost_optional/tutorial/optional_references.html

  2. Andrew Melim

    @cbeall3 Can you try compiling this with a C++11 compiler on a non-MS compiler to reproduce? This seems to be a boost issue, regardless of the compiler.

  3. Andrew Melim

    Without a major re-write, there is no real way to get around this issue. I'm adding a check in cmake to define the variable

    BOOST_OPTIONAL_ALLOW_BINDING_TO_RVALUES
    

    in the preprocessor to disable the boost assertion. Unit tests pass with the definition, but I think support for 1.56 should be given cautiously for now.

  4. Chris Beall reporter

    Yes, we still have this workaround. With Boost 1.59 the flag to disable is BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES

    From http://www.boost.org/doc/libs/1_59_0/boost/optional/optional.hpp

    template <class To, class From>
    void prevent_binding_rvalue_ref_to_optional_lvalue_ref()
    {
    #ifndef BOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES
      BOOST_STATIC_ASSERT_MSG(
        !boost::is_lvalue_reference<To>::value || !boost::is_rvalue_reference<From>::value, 
        "binding rvalue references to optional lvalue references is disallowed");
    #endif    
    }
    
  5. Log in to comment