Boost C++ Libraries: Ticket #3437: Unreachable code warning in Boost::property_tree macro https://svn.boost.org/trac10/ticket/3437 <p> The <code>BOOST_PROPERTY_TREE_THROW</code> macro us defined as follows: </p> <div class="wiki-code"><div class="code"><pre> <span class="c1">// Throwing macro to avoid no return warnings portably</span> <span class="cp"># define BOOST_PROPERTY_TREE_THROW(e) { throw_exception(e); std::exit(1); }</span> </pre></div></div><p> When using <strong>MSVS v8.0</strong> with warning level 4, this line generates warning 4702, unreachable code. </p> <h3 class="section" id="WhyThisMatters">Why This Matters</h3> <p> Although much of warning level 4 is arguably MORE than necessary, unreachable code warnings can help find code one thought should execute, as well as trim code the indeed is unreachable. This warning should NOT, in my opinion, be disabled project wide, unlike certain other level 4 warnings. Further, I prefer to set warnings as errors to ensure I follow my own advice. </p> <h3 class="section" id="Where">Where</h3> <p> The source of this defect is the BOOST_PROPERTY_TREE_THROW macro, found in <code>property_tree/ptree_fwd.hpp</code>, v55966, on line 139. </p> <p> Link: [source:trunk/boost/property_tree/ptree_fwd.hpp@55966#L139] </p> <h3 class="section" id="PossibleResolutions">Possible Resolutions</h3> <p> For whatever reason -- although I assume it is related to templates -- <code># pragma warning(disable: 4702)</code> won't disable this warning, which essentially means the offending unreachable code must be removed; however, I think it's there to provide an exit when exceptions are disabled. Would it be better to provide a different macros based on exception state? I believe this is how MS implements this for the STL... </p> <p> Perhaps [source:trunk/boost/throw_exception.hpp boost/throw_exception.hpp] should be evaluated? If only for the <code>BOOST_NO_EXCEPTIONS</code> macro. </p> <h3 class="section" id="Recreating">Recreating</h3> <p> Recreation can be done as follows: </p> <ul><li>Open MSVS </li><li>Create a new console app </li><li>add "existing" file [source:trunk/lib/property_tree/examples/debug_settings.cpp@55966] to the project </li><li>add include of stdafx.h to debug_settings.cpp </li><li>set properties: <ul><li>warning level 4 </li><li>warnings as errors </li><li>add boost location to the include search path </li></ul></li><li>build the project </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3437 Trac 1.4.3 mloskot <mateusz@…> Sat, 03 Oct 2009 21:35:11 GMT cc changed https://svn.boost.org/trac10/ticket/3437#comment:1 https://svn.boost.org/trac10/ticket/3437#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">Scott</span> <span class="trac-author">Bailey</span> <span class="trac-author">&lt;Bailey@…&gt;</span> <span class="trac-author">mateusz@…</span> added; <span class="trac-author">Scott Bailey &lt;Bailey@…&gt;</span> removed </li> </ul> Ticket Sebastian Redl Sun, 04 Oct 2009 12:16:52 GMT owner, status changed https://svn.boost.org/trac10/ticket/3437#comment:2 https://svn.boost.org/trac10/ticket/3437#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">kaalus</span> to <span class="trac-author">Sebastian Redl</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Sebastian Redl Wed, 17 Feb 2010 17:54:13 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3437#comment:3 https://svn.boost.org/trac10/ticket/3437#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Changed BOOST_PROPERTY_TREE_THROW to be an alias for BOOST_THROW_EXCEPTION. If that macro causes warnings, at least there's a central place to fix them. </p> Ticket