Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Optional] Compilation error with boost::optional in Boost 1.49 and GCC 4.4.6
From: Jonathan Jones (Jonathan.Jones_at_[hidden])
Date: 2012-04-27 15:47:23


Hello,

The following code fails to compile when using GCC 4.4.6 and boost::optional from Boost 1.49:

    #include <boost/optional/optional.hpp>
    #include <boost/type_traits/is_convertible.hpp>

    struct grill
    {
        template<typename U>
        grill (U)
        {}
    };

    template<typename T>
    struct bar
    {
        template<typename U>
        bar (U,
             typename boost::is_convertible<U,T>::type* = 0)
        {}
    };

    void foo()
    {
        typedef bar<grill> data_type;

        boost::optional<data_type> opt;
        boost::optional<data_type> opt2(opt); // this line
        (void)opt2;
    }

Here are the error messages (I apologize for the long lines, I shortened them as much as possible by truncating the header paths):

type_traits/is_convertible.hpp: In instantiation of ‘const bool boost::detail::is_convertible_basic_impl<boost::optional_detail::optional_base<bar<grill> >&, grill>::value’:
type_traits/is_convertible.hpp:329: instantiated from ‘const bool boost::detail::is_convertible_impl<boost::optional_detail::optional_base<bar<grill> >, grill>::value’
type_traits/is_convertible.hpp:452: instantiated from ‘boost::is_convertible<boost::optional_detail::optional_base<bar<grill> >, grill>’
optional/optional.hpp:604: instantiated from ‘boost::optional<T>::optional(const boost::optional<T>&) [with T = bar<grill>]’
optional.cpp:25: instantiated from here
optional/optional.hpp:285: error: ‘boost::optional_detail::optional_base<T>::optional_base(const boost::optional_detail::optional_base<T>&) [with T = bar<grill>]’ is protected
type_traits/is_convertible.hpp:170: error: within this context
type_traits/is_convertible.hpp:170: error: initializing argument 1 of ‘grill::grill(U) [with U = boost::optional_detail::optional_base<bar<grill> >]’
optional/optional.hpp:308: error: ‘boost::optional_detail::optional_base<T>::~optional_base() [with T = bar<grill>]’ is protected
type_traits/is_convertible.hpp:170: error: within this context

This reproduction case is distilled from a real world example (not my code) where bar=boost::fusion::vector1 and grill=boost::function<void()>

The code compiles fine using the same compiler and Boost 1.44.

Any ideas on the root of the problem?

Thanks in advance!
Jon


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net