Boost C++ Libraries: Ticket #7964: 'boost::system::error_code::unspecified_bool_type' : forcing value to bool 'true' or 'false' (performance warning) https://svn.boost.org/trac10/ticket/7964 <p> I'm getting the following warning on MSVC 11.0 when using boost::system::error_code in an if() statement: </p> <p> warning C4800: 'boost::system::error_code::unspecified_bool_type' : forcing value to bool 'true' or 'false' (performance warning) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7964 Trac 1.4.3 viboes Sun, 03 Feb 2013 18:49:25 GMT <link>https://svn.boost.org/trac10/ticket/7964#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7964#comment:1</guid> <description> <p> Please, could you add a little bit more context on the compiler error? </p> </description> <category>Ticket</category> </item> <item> <author>szx <szx@…></author> <pubDate>Sun, 03 Feb 2013 19:07:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7964#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7964#comment:2</guid> <description> <p> Strangely enough it seems to only appear in lambda functions because this code compiles without warnings: </p> <p> #include &lt;boost/system/error_code.hpp&gt; </p> <p> void f(const boost::system::error_code &amp;error) { </p> <blockquote> <p> if (error) {} </p> </blockquote> <p> } </p> <p> int main() { </p> <blockquote> <p> f(boost::system::error_code()); </p> </blockquote> <p> } </p> <p> while the following one </p> <p> #include &lt;boost/system/error_code.hpp&gt; int main() { </p> <blockquote> <p> auto lambda = [](const boost::system::error_code &amp;error) { </p> <blockquote> <p> if (error) {} </p> </blockquote> <p> }; </p> </blockquote> <p> } </p> <p> results in </p> <p> test.cpp(6): warning C4800: 'boost::system::error_code::unspecified_bool_type' : forcing value to bool 'true' or 'false' (performance warning) </p> <p> It's probably a compiler bug then I would guess. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Sat, 02 Mar 2013 22:34:59 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7964#comment:3 https://svn.boost.org/trac10/ticket/7964#comment:3 <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">fixed</span> </li> </ul> <p> I was able to reproduce this warning, but I don't see any short term fix. Seems like the warning is an artifact of the unspecified_bool_type idiom. </p> <p> The longer term fix is for boost.system to use the C++11 explicit conversion operator, as is specified for the standard library's version of these classes. That change has now been made (changeset 83210) for compilers that support the C++11 explicit conversion operator, such as late model gcc and VC++ November 2012 CTP. On that basis, the issue is being closed. </p> <p> Thanks, </p> <p> --Beman </p> <p> </p> Ticket