[exception] Unreachable returns (was [log] Comments)

On 15 March 2010 10:45, Vladimir Prus <ghost@cs.msu.su> wrote:
* I see lots of warnings in slim_string.cpp, e.g:
../../../../libs/log/src/slim_string.cpp:237: warning: control reaches end of non-void function
I'd recommend working with maintainer of boost/throw_exception.hpp to add noreturn attributes on gcc, and silence the warning in other ways on other compilers.
I think Boost.Exception already does that (http://www.boost.org/boost/exception/detail/attribute_noreturn.hpp) but this is something I've been meaning to ask about, as I had to deal with it for iostreams. Our normal solution is to use BOOST_UNREACHABLE_RETURN (http://tinyurl.com/yjjdzsh), but that doesn't work for compilers that don't understand a 'noreturn' attribute. I hacked together my own version (http://www.boost.org/boost/iostreams/detail/config/unreachable_return.hpp) but it's only a short term solution and could break if throw_exception changes. It would be nice to have a proper solution in Boost.Exception, or maybe there already is one and I missed it? Daniel

On Tue, Mar 16, 2010 at 5:41 PM, Daniel James <dnljms@gmail.com> wrote:
It would be nice to have a proper solution in Boost.Exception, or maybe there already is one and I missed it?
I am not sure what you mean by "proper", I just fix warnings when users report them. So if there is no warning it's all good, right? Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode

On 17 March 2010 03:23, Emil Dotchevski <emildotchevski@gmail.com> wrote:
On Tue, Mar 16, 2010 at 5:41 PM, Daniel James <dnljms@gmail.com> wrote:
It would be nice to have a proper solution in Boost.Exception, or maybe there already is one and I missed it?
I am not sure what you mean by "proper", I just fix warnings when users report them. So if there is no warning it's all good, right?
But this isn't a warning in your code so you can't fix them, you should supply the tool for others to fix them in their code. And the only reason there isn't a warning is because I used a fragile hack (it's fragile because it depends on undocumented knowledge of the implementation of Boost.Exception, so if you change it in the future, it'll break). The problem is functions like this: int foo() { boost::throw_exception(my_exception()); } This causes a compiler (I think it was Sun) to issue a 'no return statement' error, so it's changed to: int foo() { boost::throw_exception(my_exception()); return 0; } That fixes the error, but now there's a Visual C++ warning about unreachable code. Daniel
participants (2)
-
Daniel James
-
Emil Dotchevski