typeinfo and exceptions

Tim Janik timj@gtk.org
Mon Mar 7 10:42:00 GMT 2005

hi all.

i really fail to see what i'm doing wrong in the following code:

struct Exception : std::exception {
   Exception (const char *format, ...) __attribute__((__format__ (__printf__, 2, 3)));
struct Obj {
   Obj () { throw Exception ("%s: error", typeid (this).name()); }
try { Obj a; } catch (std::exception &e) {
   printf ("exception: what(): %s\n", e.what());

it does however produce garbage (with 3.3 and 3.4) instead of Obj's typename:
exception: what(): 44`l$@: error

i have attached a full test case with 2 throw statements that
will both produce a garbage typename. i'm not sure this isn't
a compiler bug, so any help is apprechiated.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: stackthrow.cc
Type: text/x-c++src
Size: 1193 bytes
Desc: stackthrow.cc
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20050307/4568a769/attachment.bin>

More information about the Gcc-bugs mailing list