Boost C++ Libraries: Ticket #6454: Problem when using phoenix::_if with boost::optional in Spirit https://svn.boost.org/trac10/ticket/6454 <p> A rule that yields a boost::optional as attribute won't compile when using qi::_1 as condition for phoenix::_if. However, if you add a phoenix statement after the if_ statement the rule compiles. </p> <blockquote> <p> <em>Doesn't compile qi::rule&lt;Iter, boost::optional&lt;int&gt;()&gt; rule_a = </em></p> <blockquote> <p> (-qi::int_)[ </p> <blockquote> <p> phx::if_(qi::_1)[ </p> <blockquote> <p> phx::nothing </p> </blockquote> <p> ] <em>Uncomment next line and it compiles </em> , phx::nothing </p> </blockquote> <p> ] </p> </blockquote> </blockquote> <blockquote> <p> ; </p> </blockquote> <p> It doesn't help if you use another operator than - </p> <blockquote> <p> <em>Doesn't compile qi::rule&lt;Iter, boost::optional&lt; boost::variant&lt;int, double&gt; &gt;() &gt; rule_b = </em></p> <blockquote> <p> (qi::int_ | qi::double_ | qi::eps)[ </p> <blockquote> <p> phx::if_(qi::_1)[ </p> <blockquote> <p> phx::nothing </p> </blockquote> <p> ] <em>Uncomment next line and it compiles </em> , phx::nothing </p> </blockquote> <p> ] </p> </blockquote> <p> ; </p> </blockquote> <p> The error doesn't manifest if you don't refer to qi::_1 </p> <blockquote> <p> <em>Compiles qi::rule&lt;Iter, boost::optional&lt; boost::variant&lt;int, double&gt; &gt;() &gt; rule_c = </em></p> <blockquote> <p> (qi::int_ | qi::double_ | qi::eps)[ </p> <blockquote> <p> phx::if_(phx::val(true))[ </p> <blockquote> <p> phx::nothing </p> </blockquote> <p> ] </p> </blockquote> <p> ] </p> </blockquote> <p> ; </p> </blockquote> <p> It also works if you refer to qi::_1 but don't use phoenix::if_ </p> <blockquote> <p> <em>Compiles qi::rule&lt;Iter, boost::optional&lt;int&gt;()&gt; rule_d = </em></p> <blockquote> <p> (-qi::int_)[ </p> <blockquote> <p> std::cout &lt;&lt; qi::_1 </p> </blockquote> <p> ] </p> </blockquote> <p> ; </p> </blockquote> <p> Doing the same thing as in rule_a and rule_b outside of Spirit semantic actions also works </p> <blockquote> <p> <em>Compiles phx::if_(arg1)[ </em></p> <blockquote> <p> phx::nothing </p> </blockquote> <p> ] (boost::optional&lt;int&gt;(5)); </p> </blockquote> <p> The problem doesn't seem to occur when using Phoenix v2 only v3 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6454 Trac 1.4.3 Öyvind Strand <oyvind.strand@…> Thu, 26 Jan 2012 18:05:47 GMT attachment set https://svn.boost.org/trac10/ticket/6454 https://svn.boost.org/trac10/ticket/6454 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test_phoenix_if.cpp</span> </li> </ul> <p> Self-contained test case </p> Ticket