Boost C++ Libraries: Ticket #10785: Lambda assignment fails to compile in 1.57.0 https://svn.boost.org/trac10/ticket/10785 <p> The following code used to work. From Boost 1.57.0 it does not compile with Clang 3.4, 3.5, 3.6 and Apple Clang. </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/function.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/lambda/lambda.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/lambda/bind.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">add</span><span class="p">(</span><span class="kt">int</span> <span class="n">a</span><span class="p">,</span> <span class="kt">int</span> <span class="n">b</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">a</span><span class="o">+</span><span class="n">b</span><span class="p">;</span> <span class="p">}</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">function</span><span class="o">&lt;</span><span class="kt">int</span> <span class="p">(</span><span class="kt">int</span><span class="p">,</span> <span class="kt">int</span><span class="p">)</span><span class="o">&gt;</span> <span class="n">fuse</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">lambda</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="o">&amp;</span><span class="n">add</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">lambda</span><span class="o">::</span><span class="n">_1</span><span class="p">,</span> <span class="o">-</span><span class="n">boost</span><span class="o">::</span><span class="n">lambda</span><span class="o">::</span><span class="n">_2</span><span class="p">);</span> <span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="n">fuse</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">6</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">a</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> The compiler error reads: </p> <pre class="wiki">In file included from boost_lambda.cpp:3: In file included from /Users/dolfim/src/boost_1_57_0/boost/lambda/lambda.hpp:14: In file included from /Users/dolfim/src/boost_1_57_0/boost/lambda/core.hpp:46: /Users/dolfim/src/boost_1_57_0/boost/lambda/detail/lambda_traits.hpp:256:58: error: cannot form a reference to 'void' typename detail::IF&lt;boost::is_function&lt;T&gt;::value, T&amp;, const T&gt;::RET ^ /Users/dolfim/src/boost_1_57_0/boost/lambda/detail/operators.hpp:148:98: note: in instantiation of template class 'boost::lambda::const_copy_argument&lt;const void&gt;' requested here BOOST_LAMBDA_BE2(BOOST_LAMBDA_COMMA_OPERATOR_NAME, other_action&lt;comma_action&gt;, const A, const B, const_copy_argument) ^ /Users/dolfim/src/boost_1_57_0/boost/lambda/detail/operators.hpp:63:20: note: expanded from macro 'BOOST_LAMBDA_BE2' tuple&lt;typename CONVERSION &lt;CONSTA&gt;::type, lambda_functor&lt;Arg&gt; &gt; \ ^ /Users/dolfim/src/boost_1_57_0/boost/lambda/detail/operators.hpp:148:18: note: while substituting deduced template arguments into function template 'operator,' [with A = void, Arg = boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt;] BOOST_LAMBDA_BE2(BOOST_LAMBDA_COMMA_OPERATOR_NAME, other_action&lt;comma_action&gt;, const A, const B, const_copy_argument) ^ /Users/dolfim/src/boost_1_57_0/boost/lambda/detail/operators.hpp:145:42: note: expanded from macro 'BOOST_LAMBDA_COMMA_OPERATOR_NAME' #define BOOST_LAMBDA_COMMA_OPERATOR_NAME operator, ^ /Users/dolfim/src/boost_1_57_0/boost/lambda/detail/operators.hpp:65:78: note: expanded from macro 'BOOST_LAMBDA_BE2' &gt; \ ^ /Users/dolfim/src/boost_1_57_0/boost/type_traits/is_copy_constructible.hpp:104:24: note: in instantiation of template class 'boost::detail::is_copy_constructible_impl2&lt;false, boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt; &gt; &gt;' requested here boost::detail::is_copy_constructible_impl2&lt; ^ /Users/dolfim/src/boost_1_57_0/boost/config/suffix.hpp:394:72: note: expanded from macro 'BOOST_STATIC_CONSTANT' # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment ^ /Users/dolfim/src/boost_1_57_0/boost/type_traits/is_copy_constructible.hpp:113:71: note: in instantiation of template class 'boost::detail::is_copy_constructible_impl&lt;boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt; &gt; &gt;' requested here BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_copy_constructible,T,::boost::detail::is_copy_constructible_impl&lt;T&gt;::value) ^ /Users/dolfim/src/boost_1_57_0/boost/type_traits/detail/bool_trait_def.hpp:61:30: note: expanded from macro 'BOOST_TT_AUX_BOOL_TRAIT_DEF1' BOOST_TT_AUX_BOOL_C_BASE(C) \ ^ /Users/dolfim/src/boost_1_57_0/boost/type_traits/detail/bool_trait_def.hpp:55:81: note: expanded from macro 'BOOST_TT_AUX_BOOL_C_BASE' # define BOOST_TT_AUX_BOOL_C_BASE(C) : public ::boost::integral_constant&lt;bool,C&gt; ^ /Users/dolfim/src/boost_1_57_0/boost/type_traits/has_trivial_copy.hpp:36:76: note: in instantiation of template class 'boost::is_copy_constructible&lt;boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt; &gt; &gt;' requested here BOOST_STATIC_CONSTANT(bool, value = BOOST_HAS_TRIVIAL_COPY(T) &amp;&amp; boost::is_copy_constructible&lt;T&gt;::value); ^ /Users/dolfim/src/boost_1_57_0/boost/config/suffix.hpp:394:72: note: expanded from macro 'BOOST_STATIC_CONSTANT' # define BOOST_STATIC_CONSTANT(type, assignment) static const type assignment ^ /Users/dolfim/src/boost_1_57_0/boost/type_traits/has_trivial_copy.hpp:62:78: note: in instantiation of template class 'boost::detail::has_trivial_copy_impl&lt;boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt; &gt; &gt;' requested here BOOST_TT_AUX_BOOL_TRAIT_DEF1(has_trivial_copy_constructor,T,::boost::detail::has_trivial_copy_impl&lt;T&gt;::value) ^ /Users/dolfim/src/boost_1_57_0/boost/type_traits/detail/bool_trait_def.hpp:61:30: note: expanded from macro 'BOOST_TT_AUX_BOOL_TRAIT_DEF1' BOOST_TT_AUX_BOOL_C_BASE(C) \ ^ /Users/dolfim/src/boost_1_57_0/boost/type_traits/detail/bool_trait_def.hpp:55:81: note: expanded from macro 'BOOST_TT_AUX_BOOL_C_BASE' # define BOOST_TT_AUX_BOOL_C_BASE(C) : public ::boost::integral_constant&lt;bool,C&gt; ^ /Users/dolfim/src/boost_1_57_0/boost/function/function_template.hpp:939:20: note: in instantiation of template class 'boost::has_trivial_copy_constructor&lt;boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt; &gt; &gt;' requested here if (boost::has_trivial_copy_constructor&lt;Functor&gt;::value &amp;&amp; ^ /Users/dolfim/src/boost_1_57_0/boost/function/function_template.hpp:722:13: note: in instantiation of function template specialization 'boost::function2&lt;int, int, int&gt;::assign_to&lt;boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt; &gt; &gt;' requested here this-&gt;assign_to(f); ^ /Users/dolfim/src/boost_1_57_0/boost/function/function_template.hpp:1071:5: note: in instantiation of function template specialization 'boost::function2&lt;int, int, int&gt;::function2&lt;boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt; &gt; &gt;' requested here base_type(f) ^ boost_lambda.cpp:14:44: note: in instantiation of function template specialization 'boost::function&lt;int (int, int)&gt;::function&lt;boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::action&lt;3, boost::lambda::function_action&lt;3, boost::lambda::detail::unspecified&gt; &gt;, boost::tuples::tuple&lt;int (*const)(int, int), const boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;FIRST&gt; &gt;, const boost::lambda::lambda_functor&lt;boost::lambda::lambda_functor_base&lt;boost::lambda::unary_arithmetic_action&lt;boost::lambda::minus_action&gt;, boost::tuples::tuple&lt;boost::lambda::lambda_functor&lt;boost::lambda::placeholder&lt;SECOND&gt; &gt;, 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; &gt; &gt;, 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; &gt; &gt; &gt;' requested here boost::function&lt;int (int, int)&gt; fuse = boost::lambda::bind(&amp;add, boost::lambda::_1, -boost::lambda::_2); ^ 1 error generated. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10785 Trac 1.4.3 Marshall Clow Wed, 12 Nov 2014 19:53:37 GMT <link>https://svn.boost.org/trac10/ticket/10785#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10785#comment:1</guid> <description> <p> More info: this compiles fine for me on clang with <code>-std=c++11</code> or <code>-std=c++14</code>, but fails with <code>-std=c++03</code> </p> <p> This is the part that causes the problem: </p> <pre class="wiki"> boost::function&lt;int (int, int)&gt; fuse = boost::lambda::bind(&amp;add, boost::lambda::_1, -boost::lambda::_2); </pre><p> and commenting out the first line removes the error. </p> </description> <category>Ticket</category> </item> <item> <author>Jack Howarth <howarth.at.mailing.lists@…></author> <pubDate>Mon, 20 Apr 2015 12:11:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10785#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10785#comment:2</guid> <description> <p> This issue also exists in the boost 1.58 release. </p> </description> <category>Ticket</category> </item> </channel> </rss>