[Boost-bugs] [Boost C++ Libraries] #9134: Code that uses BOOST_THROW_EXCEPTION produces a lot of "result may be used uninitialized (...)" warnings in certain conditions

Subject: [Boost-bugs] [Boost C++ Libraries] #9134: Code that uses BOOST_THROW_EXCEPTION produces a lot of "result may be used uninitialized (...)" warnings in certain conditions
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-09-19 12:45:45


#9134: Code that uses BOOST_THROW_EXCEPTION produces a lot of "result may be used
uninitialized (...)" warnings in certain conditions
-------------------------------------------+----------------------------
 Reporter: Adam Romanek <romanek.adam@…> | Owner: emildotchevski
     Type: Patches | Status: new
Milestone: To Be Determined | Component: exception
  Version: Boost 1.54.0 | Severity: Problem
 Keywords: |
-------------------------------------------+----------------------------
 The problem appears when using g++ with `-Wuninitialized -fno-exceptions
 -O3` flags.

 Given a simple test:
 {{{
 #include <boost/lexical_cast.hpp>

 int main() {
   return boost::lexical_cast<int>("");
 }
 }}}

 when compiled using g++ v4.6.3 produces the following output:
 {{{
 $ 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<Target,
 Source>::lexical_cast_impl(const Source&) [with Target = int, Source =
 const char*]’:
 boost/boost/lexical_cast.hpp:2353:24: warning: ‘result’ may be used
 uninitialized in this function [-Wuninitialized]
 }}}

 Please note that this problem appears only when using `-O3` optimization
 level.

 One way of fixing this issue is to add `BOOST_ATTRIBUTE_NORETURN` to
 `boost::throw_exception()` declaration in `boost/throw_exception.hpp`, as
 shown in the attached patch.

 It should be safe to do so, as the documentation of
 `boost::throw_exception()` says that:

> (...) Callers of throw_exception are allowed to assume that the function
 never returns (...)

 This solves the issue completely.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9134>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:14 UTC