Opened 12 years ago

Closed 12 years ago

#4486 closed Bugs (invalid)

C2166: l-value specifies const object error using MSVC 1600 without _DEBUG

Reported by: Claudio Bley Owned by: No-Maintainer
Milestone: Boost 1.44.0 Component: lambda
Version: Boost 1.43.0 Severity: Problem
Keywords: Cc:

Description

Hi.

For the following test case:

#include <set>
#include <string>
#include <algorithm>
#include <boost/function_output_iterator.hpp>

#ifdef USE_BLL
#  include <boost/lambda/lambda.hpp>
#  include <boost/lambda/bind.hpp>
using namespace boost::lambda;
#else
#  include <boost/bind.hpp>
using namespace boost;
#endif

int main(int argc, char *argv[])
{
    int a[] = {1, 2, 3, 4};
    typedef std::set<int> aSet;
    typedef std::pair<aSet::iterator, bool> (aSet::*si)(const aSet::value_type&);

    aSet s;
    si set_insert = &aSet::insert;

    std::copy(a, a + sizeof(a) / sizeof(*a),
              boost::make_function_output_iterator( bind(set_insert, &s, _1)));
}

I receive this error when compiling in "Release mode" (I'm using CMake) using Visual Studio 10 x86 on Windows XP SP3 with :

C:\Programme\Boost\include\boost/tuple/detail/tuple_basic.hpp(383) : error C2166: l-value specifies const object
        C:\Programme\Boost\include\boost/tuple/detail/tuple_basic.hpp(382) : while compiling class template member function 'boost::tuples::cons<HT,TT> &boost::tuples::cons<HT,TT>::operator =(const boost::tuples::cons<HT,TT> &)'
        with
        [
            HT=std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>>,bool> (__thiscall std::set<int>::* const )(const int &),
            TT=boost::tuples::cons<std::set<int> *const ,boost::tuples::cons<const boost::arg<1>,boost::tuples::detail::map_tuple_to_cons<boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>::type>>
        ]
        C:\Programme\Boost\include\boost/tuple/detail/tuple_basic.hpp(535) : see reference to class template instantiation 'boost::tuples::cons<HT,TT>' being compiled
        with
        [
            HT=std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>>,bool> (__thiscall std::set<int>::* const )(const int &),
            TT=boost::tuples::cons<std::set<int> *const ,boost::tuples::cons<const boost::arg<1>,boost::tuples::detail::map_tuple_to_cons<boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type,boost::tuples::null_type>::type>>
        ]
        C:\Programme\Boost\include\boost/lambda/detail/lambda_functor_base.hpp(422) : see reference to class template instantiation 'boost::tuples::tuple<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>' being compiled
        with
        [
            T0=std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>>,bool> (__thiscall std::set<int>::* const )(const int &),
            T1=std::set<int> *const ,
            T2=const boost::arg<1>,
            T3=boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,
            T4=boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,
            T5=boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,
            T6=boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,
            T7=boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,
            T8=boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,
            T9=boost::lambda::detail::bind_traits<boost::tuples::null_type>::type
        ]
        C:\Programme\Boost\include\boost/lambda/detail/lambda_functors.hpp(140) : see reference to class template instantiation 'boost::lambda::lambda_functor_base<Act,Args>' being compiled
        with
        [
            Act=boost::lambda::action<3,boost::lambda::function_action<3>>,
            Args=boost::tuples::tuple<std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>>,bool> (__thiscall std::set<int>::* const )(const int &),std::set<int> *const ,const boost::arg<1>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>
        ]
        C:\sandbox\lambdabug\bug.cpp(25) : see reference to class template instantiation 'boost::lambda::lambda_functor<T>' being compiled
        with
        [
            T=boost::lambda::lambda_functor_base<boost::lambda::action<3,boost::lambda::function_action<3>>,boost::tuples::tuple<std::pair<std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>>,bool> (__thiscall std::set<int>::* const )(const int &),std::set<int> *const ,const boost::arg<1>,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>
        ]
NMAKE : fatal error U1077: 'C:\PROGRA~1\MICROS~2.0\VC\bin\cl.exe' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Programme\Microsoft Visual Studio 10.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Programme\Microsoft Visual Studio 10.0\VC\BIN\nmake.exe"' : return code '0x2'
Stop.

The command line used to compile is the following:

cl
  /DWIN32
  /D_WINDOWS
  /D_SCL_SECURE_NO_WARNINGS
  /Zm1000
  /DUSE_BLL
  -IC:\Programme\Boost\include
  /Fobug.cpp.obj
  -c C:\sandbox\lambdabug\bug.cpp

When defining the _DEBUG preprocessor variable, or when using Boost Bind instead it compiles successfully.

Change History (1)

comment:1 by Steven Watanabe, 12 years ago

Resolution: invalid
Status: newclosed

Lambda functors are not Assignable. function_output_iterator requires an Assignable function object.

Note: See TracTickets for help on using tickets.