Boost C++ Libraries: Ticket #9134: Code that uses BOOST_THROW_EXCEPTION produces a lot of "result may be used uninitialized (...)" warnings in certain conditions https://svn.boost.org/trac10/ticket/9134 <p> The problem appears when using g++ with <code>-Wuninitialized -fno-exceptions -O3</code> flags. </p> <p> Given a simple test: </p> <pre class="wiki">#include &lt;boost/lexical_cast.hpp&gt; int main() { return boost::lexical_cast&lt;int&gt;(""); } </pre><p> when compiled using g++ v4.6.3 produces the following output: </p> <pre class="wiki">$ g++ test.cpp -Iboost -fno-exceptions -Wuninitialized -O3 -c In file included from test.cpp:1:0: boost/boost/lexical_cast.hpp: In static member function ‘static Target boost::detail::lexical_cast_do_cast&lt;Target, Source&gt;::lexical_cast_impl(const Source&amp;) [with Target = int, Source = const char*]’: boost/boost/lexical_cast.hpp:2353:24: warning: ‘result’ may be used uninitialized in this function [-Wuninitialized] </pre><p> Please note that this problem appears only when using <code>-O3</code> optimization level. </p> <p> One way of fixing this issue is to add <code>BOOST_ATTRIBUTE_NORETURN</code> to <code>boost::throw_exception()</code> declaration in <code>boost/throw_exception.hpp</code>, as shown in the attached patch. </p> <p> It should be safe to do so, as the documentation of <code>boost::throw_exception()</code> says that: </p> <blockquote class="citation"> <p> (...) Callers of throw_exception are allowed to assume that the function never returns (...) </p> </blockquote> <p> This solves the issue completely. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9134 Trac 1.4.3 Adam Romanek <romanek.adam@…> Thu, 19 Sep 2013 12:46:45 GMT attachment set https://svn.boost.org/trac10/ticket/9134 https://svn.boost.org/trac10/ticket/9134 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost_throw_exception_hpp.patch</span> </li> </ul> Ticket Adam Romanek <romanek.adam@…> Thu, 19 Sep 2013 12:46:58 GMT attachment set https://svn.boost.org/trac10/ticket/9134 https://svn.boost.org/trac10/ticket/9134 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cpp</span> </li> </ul> Ticket