Opened 9 years ago
#9134 new Patches
Code that uses BOOST_THROW_EXCEPTION produces a lot of "result may be used uninitialized (...)" warnings in certain conditions
Reported by: | Owned by: | Emil Dotchevski | |
---|---|---|---|
Milestone: | To Be Determined | Component: | exception |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description
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.
Attachments (2)
Change History (2)
by , 9 years ago
Attachment: | boost_throw_exception_hpp.patch added |
---|