[exception] warnings on top of trunk

/opt/boost/trunk/stage/gcc-4.4.4-release/include/boost/exception/detail/exception_ptr.hpp: In function ‘void boost::rethrow_exception(const boost::exception_ptr&)’: /opt/boost/trunk/stage/gcc-4.4.4-release/include/boost/exception/detail/exception_ptr.hpp:458: warning: ‘noreturn’ function does return Is it cool for me to remove this attribute? -- Bryce Lelbach aka wash boost-spirit.com px.cct.lsu.edu github.com/lll-project

On May 23, 2011, at 7:45 AM, Bryce Lelbach wrote:
/opt/boost/trunk/stage/gcc-4.4.4-release/include/boost/exception/detail/exception_ptr.hpp: In function ‘void boost::rethrow_exception(const boost::exception_ptr&)’: /opt/boost/trunk/stage/gcc-4.4.4-release/include/boost/exception/detail/exception_ptr.hpp:458: warning: ‘noreturn’ function does return
Is it cool for me to remove this attribute?
Bryce - Do you mean this function?
BOOST_ATTRIBUTE_NORETURN inline void rethrow_exception( exception_ptr const & p ) { BOOST_ASSERT(p); p.ptr_->rethrow(); }
I don't see any way that function can return. Maybe boost::exception::detail::impl::rethrow should be marked "noreturn" instead. -- Marshall Marshall Clow Idio Software <mailto:mclow.lists@gmail.com> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki

GCC documentation: noreturn A few standard library functions, such as abort and exit, cannot return. GCC knows this automatically. Some programs define their own functions that never return. You can declare them noreturn to tell the compiler this fact. [snip] The noreturn keyword does not affect the exceptional path when that applies: a noreturn-marked function may still return to the caller by throwing an exception or calling longjmp. p.ptr_->rethrow() is not marked as noreturn, and it throws an exception, which makes it nonsensical IMHO. It does actually exit. Example: #include <stdlib.h> #include <exception> #include <stdlib.h> __attribute__((noreturn)) void foo1 (void); void foo2 (void); __attribute__((noreturn)) void foo1 (void) { foo2(); } void foo2 (void) { } __attribute__((noreturn)) void bar1 (void); void bar2 (void); __attribute__((noreturn)) void bar1 (void) { bar2(); exit(0); } void bar2 (void) { } __attribute__((noreturn)) void buzz1 (void); __attribute__((noreturn)) void buzz2 (void); __attribute__((noreturn)) void buzz1 (void) { buzz2(); } __attribute__((noreturn)) void buzz2 (void) { } __attribute__((noreturn)) void yack1 (void); __attribute__((noreturn)) void yack2 (void); __attribute__((noreturn)) void yack1 (void) { yack2(); } __attribute__((noreturn)) void yack2 (void) { throw std::exception(); } int main (void) { foo1(); bar1(); buzz1(); yack1(); } Emits: [10:22:04]:wash@vega.cct.lsu.edu:/home/wash/sandbox$ g++ -Wall -Wextra -DNDEBUG -O3 attribute_no_return.cpp -o attribute_no_return attribute_no_return.cpp: In function ‘void buzz2()’: attribute_no_return.cpp:20: warning: ‘noreturn’ function does return attribute_no_return.cpp: In function ‘void foo1()’: attribute_no_return.cpp:7: warning: ‘noreturn’ function does return On GCC 4.4.4, RHEL 6.0, x86-64. This warning is in fact valid.
BOOST_ATTRIBUTE_NORETURN inline void rethrow_exception( exception_ptr const & p ) { BOOST_ASSERT(p); p.ptr_->rethrow(); }
p.ptr is a shared_ptr to an exception_detail::clone_base. rethrow() is a pure virtual function. Therefore, there is no gurantee that rethrow() won't exit, and if it does, then rethrow_exception will exit, which could be catastrophic. Not to mention the possibilities if exceptions are disabled (not sure if rethrow_exception is even available in that case). rethrow_exception should call abort() after rethrow() to ensure that it doesn't return, or attribute noreturn should be removed. It is just an optimization... -- Bryce Lelbach aka wash boost-spirit.com px.cct.lsu.edu github.com/lll-project

On 23 May 2011 16:44, Bryce Lelbach <blelbach@cct.lsu.edu> wrote:
p.ptr is a shared_ptr to an exception_detail::clone_base. rethrow() is a pure virtual function. Therefore, there is no gurantee that rethrow() won't exit, and if it does, then rethrow_exception will exit, which could be catastrophic.
Since the class is in a detail namespace, user code shouldn't inherit from it. So as long as the user follows our conventions, we can guarantee that it exits. And if the user doesn't, it's their responsibility.

AMDG On 05/23/2011 07:45 AM, Bryce Lelbach wrote:
/opt/boost/trunk/stage/gcc-4.4.4-release/include/boost/exception/detail/exception_ptr.hpp: In function ‘void boost::rethrow_exception(const boost::exception_ptr&)’: /opt/boost/trunk/stage/gcc-4.4.4-release/include/boost/exception/detail/exception_ptr.hpp:458: warning: ‘noreturn’ function does return
Is it cool for me to remove this attribute?
This function really doesn't return. It would be better to add the attribute to clone_base::rethrow. Emil? In Christ, Steven Watanabe

On Mon, May 23, 2011 at 7:45 AM, Bryce Lelbach <blelbach@cct.lsu.edu> wrote:
/opt/boost/trunk/stage/gcc-4.4.4-release/include/boost/exception/detail/exception_ptr.hpp: In function ‘void boost::rethrow_exception(const boost::exception_ptr&)’: /opt/boost/trunk/stage/gcc-4.4.4-release/include/boost/exception/detail/exception_ptr.hpp:458: warning: ‘noreturn’ function does return
Is it cool for me to remove this attribute?
Probably not, since it was put in to address another GCC warning. :) Try trunk revision 72127, see if it helps. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
participants (5)
-
Bryce Lelbach
-
Daniel James
-
Emil Dotchevski
-
Marshall Clow
-
Steven Watanabe