http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267

--- Comment #5 from David Keller <david.keller at litchis dot fr> 2012-08-15 
03:16:30 UTC ---
  1 #include <iostream>
  2 #include <stdexcept>
  3
  4 namespace detail {
  5
  6 inline void throw_error(bool t)
  7 {
  8     /**
  9      * If this condition is removed, (i.e. always throw)
 10      * Then the exception will be catched !!
 11      */
 12     if ( t )
 13     {
 14         std::runtime_error e("failed");
 15         throw e;
 16     }
 17 }
 18
 19 inline void this_function_is_required ( void )
 20 {
 21     std::cout << "do not remove on optimization" << std::endl;
 22 }
 23
 24 } // namespace detail
 25
 26 /**
 27  *  This exception is not catchable !
 28  */
 29 void
 30 do_throw_bad
 31     ( bool b )
 32 {
 33     // Simulate a boost::asio::error
 34     //boost::system::errc::make_error_code(
boost::system::errc::address_in_use );
 35     detail::this_function_is_required();
 36     detail::throw_error( b );
 37 }
 38
 39 /**
 40  *  Expect:
 41  *  #############
 42  *  catched bad
 43  *  ############
 44  *
 45  *  But see:
 46  *  #############
 47  *  terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error>
>'
 48  *    what():  asio: End of file
 49  *    Abort trap (core dumped)
 50  *  #############
 51  */
 52 int
 53 main
 54     ( int argc
 55     , char* argv[] )
 56 {
 57     try
 58     {
 59         do_throw_bad( argc == 1 );
 60     }
 61     catch ( std::exception const& )
 62     {
 63         std::cout << "catched" << std::endl;
 64     }
 65
 66     return 0;
 67 }
 68

Et voilĂ 

Reply via email to