Minor exception bug with unexpected

ak@muc.de ak@muc.de
Wed Mar 18 18:42:00 GMT 1998


Version:
i586-pc-linux-gnulibc1/egcs-2.91.13
gcc version egcs-2.91.13 980308 (gcc-2.8.0 release)

The appended example dumps core in __check_eh_spec. Although that
is legal in CD2 [except.special says "The unexpected() function shall 
not return"], it is still not very nice to the user. The patch 
makes unexpected() call terminate() in this case.


Thu Mar 19 03:38:17 1998  Andi Kleen  <ak@muc.de>

	* exception.cc (unexpected): Call terminate if the unexpected
	handler returns.
	(__default_unexpected): No need to call terminate here now.


*** gcc/cp/exception.cc-o	Thu Mar 19 03:31:33 1998
--- gcc/cp/exception.cc	Thu Mar 19 03:32:25 1998
***************
*** 43,53 ****
  }
  
  void
  __default_unexpected ()
  {
-   terminate ();
  }
  
  static unexpected_handler __unexpected_func __attribute__((__noreturn__))
    = __default_unexpected;
  
--- 43,52 ----
***************
*** 71,80 ****
--- 70,80 ----
  
  void
  unexpected ()
  {
    __unexpected_func ();
+   terminate(); 
  }
  
  /* C++-specific state about the current exception.
     This must match init_exception_processing().
  

Example:

#include <exception>
#include <stdio.h>
using namespace std;

class Bla { 
	const char *msg;
public:
	Bla(const char *m = "") { msg = m; } 
	const char *what() { return msg; } 
}; 

// make sure that is not inlined!
void f_ue();

void f() throw()
{
	f_ue();
}

void f_ue()
{
	throw Bla("f_ue"); 
} 

void myerr()
{
	printf("unexpected exception\n"); 
	// not standard conforming - does return.
}

main()
{	
	set_unexpected(myerr);
	f(); 
}


-Andi




More information about the Gcc-bugs mailing list