Boost C++ Libraries: Ticket #4486: C2166: l-value specifies const object error using MSVC 1600 without _DEBUG https://svn.boost.org/trac10/ticket/4486 <p> Hi. </p> <p> For the following test case: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;set&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;string&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;algorithm&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/function_output_iterator.hpp&gt;</span><span class="cp"></span> <span class="cp">#ifdef USE_BLL</span> <span class="cp"># include &lt;boost/lambda/lambda.hpp&gt;</span> <span class="cp"># include &lt;boost/lambda/bind.hpp&gt;</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">lambda</span><span class="p">;</span> <span class="cp">#else</span> <span class="cp"># include &lt;boost/bind.hpp&gt;</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="p">;</span> <span class="cp">#endif</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> <span class="p">{</span> <span class="kt">int</span> <span class="n">a</span><span class="p">[]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">};</span> <span class="k">typedef</span> <span class="n">std</span><span class="o">::</span><span class="n">set</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span> <span class="n">aSet</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">std</span><span class="o">::</span><span class="n">pair</span><span class="o">&lt;</span><span class="n">aSet</span><span class="o">::</span><span class="n">iterator</span><span class="p">,</span> <span class="kt">bool</span><span class="o">&gt;</span> <span class="p">(</span><span class="n">aSet</span><span class="o">::*</span><span class="n">si</span><span class="p">)(</span><span class="k">const</span> <span class="n">aSet</span><span class="o">::</span><span class="n">value_type</span><span class="o">&amp;</span><span class="p">);</span> <span class="n">aSet</span> <span class="n">s</span><span class="p">;</span> <span class="n">si</span> <span class="n">set_insert</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">aSet</span><span class="o">::</span><span class="n">insert</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span> <span class="o">+</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">/</span> <span class="k">sizeof</span><span class="p">(</span><span class="o">*</span><span class="n">a</span><span class="p">),</span> <span class="n">boost</span><span class="o">::</span><span class="n">make_function_output_iterator</span><span class="p">(</span> <span class="n">bind</span><span class="p">(</span><span class="n">set_insert</span><span class="p">,</span> <span class="o">&amp;</span><span class="n">s</span><span class="p">,</span> <span class="n">_1</span><span class="p">)));</span> <span class="p">}</span> </pre></div></div><p> I receive this error when compiling in "Release mode" (I'm using CMake) using Visual Studio 10 x86 on Windows XP SP3 with : </p> <pre class="wiki">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&lt;HT,TT&gt; &amp;boost::tuples::cons&lt;HT,TT&gt;::operator =(const boost::tuples::cons&lt;HT,TT&gt; &amp;)' with [ HT=std::pair&lt;std::_Tree_const_iterator&lt;std::_Tree_val&lt;std::_Tset_traits&lt;int,std::less&lt;int&gt;,std::allocator&lt;int&gt;,false&gt;&gt;&gt;,bool&gt; (__thiscall std::set&lt;int&gt;::* const )(const int &amp;), TT=boost::tuples::cons&lt;std::set&lt;int&gt; *const ,boost::tuples::cons&lt;const boost::arg&lt;1&gt;,boost::tuples::detail::map_tuple_to_cons&lt;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&gt;::type&gt;&gt; ] C:\Programme\Boost\include\boost/tuple/detail/tuple_basic.hpp(535) : see reference to class template instantiation 'boost::tuples::cons&lt;HT,TT&gt;' being compiled with [ HT=std::pair&lt;std::_Tree_const_iterator&lt;std::_Tree_val&lt;std::_Tset_traits&lt;int,std::less&lt;int&gt;,std::allocator&lt;int&gt;,false&gt;&gt;&gt;,bool&gt; (__thiscall std::set&lt;int&gt;::* const )(const int &amp;), TT=boost::tuples::cons&lt;std::set&lt;int&gt; *const ,boost::tuples::cons&lt;const boost::arg&lt;1&gt;,boost::tuples::detail::map_tuple_to_cons&lt;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&gt;::type&gt;&gt; ] C:\Programme\Boost\include\boost/lambda/detail/lambda_functor_base.hpp(422) : see reference to class template instantiation 'boost::tuples::tuple&lt;T0,T1,T2,T3,T4,T5,T6,T7,T8,T9&gt;' being compiled with [ T0=std::pair&lt;std::_Tree_const_iterator&lt;std::_Tree_val&lt;std::_Tset_traits&lt;int,std::less&lt;int&gt;,std::allocator&lt;int&gt;,false&gt;&gt;&gt;,bool&gt; (__thiscall std::set&lt;int&gt;::* const )(const int &amp;), T1=std::set&lt;int&gt; *const , T2=const boost::arg&lt;1&gt;, T3=boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type, T4=boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type, T5=boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type, T6=boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type, T7=boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type, T8=boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type, T9=boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type ] C:\Programme\Boost\include\boost/lambda/detail/lambda_functors.hpp(140) : see reference to class template instantiation 'boost::lambda::lambda_functor_base&lt;Act,Args&gt;' being compiled with [ Act=boost::lambda::action&lt;3,boost::lambda::function_action&lt;3&gt;&gt;, Args=boost::tuples::tuple&lt;std::pair&lt;std::_Tree_const_iterator&lt;std::_Tree_val&lt;std::_Tset_traits&lt;int,std::less&lt;int&gt;,std::allocator&lt;int&gt;,false&gt;&gt;&gt;,bool&gt; (__thiscall std::set&lt;int&gt;::* const )(const int &amp;),std::set&lt;int&gt; *const ,const boost::arg&lt;1&gt;,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type&gt; ] C:\sandbox\lambdabug\bug.cpp(25) : see reference to class template instantiation 'boost::lambda::lambda_functor&lt;T&gt;' being compiled with [ T=boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3,boost::lambda::function_action&lt;3&gt;&gt;,boost::tuples::tuple&lt;std::pair&lt;std::_Tree_const_iterator&lt;std::_Tree_val&lt;std::_Tset_traits&lt;int,std::less&lt;int&gt;,std::allocator&lt;int&gt;,false&gt;&gt;&gt;,bool&gt; (__thiscall std::set&lt;int&gt;::* const )(const int &amp;),std::set&lt;int&gt; *const ,const boost::arg&lt;1&gt;,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type,boost::lambda::detail::bind_traits&lt;boost::tuples::null_type&gt;::type&gt;&gt; ] 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. </pre><p> The command line used to compile is the following: </p> <pre class="wiki">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 </pre><p> When defining the _DEBUG preprocessor variable, or when using Boost Bind instead it compiles successfully. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4486 Trac 1.4.3 Steven Watanabe Thu, 07 Apr 2011 00:09:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4486#comment:1 https://svn.boost.org/trac10/ticket/4486#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Lambda functors are not Assignable. function_output_iterator requires an Assignable function object. </p> Ticket