Hi Bob, * Bob Friesenhahn wrote on Mon, Jan 11, 2010 at 05:32:15AM CET: > On Sun, 10 Jan 2010, Ralf Wildenhues wrote: > >> > >>My main comment is that it would be useful if the thrown class is > >>derived from std:exception (or one of its standard derived classes) > >>in order to flush out any issues which may stem from possible > >>partial template instantiation in libstdc++ (or pre-compiled > >>headers) as well as in the test translation unit. > > > >OK, sounds useful. Would that entail more than just something like > >this incremental addition? > > I think that the virtual what() method needs to be provided or else > you have only a partially implemented class: [...]
Yup, indeed. And we need to provide a throw()-qualified destructor as well. > But this is a better class to test with since it uses more standard > library stuff and is therefore more likely to fail if something is > wrong: [...] Thanks. I'm pushing the test with this incremental addition squashed into the first iteration of the patch, and listing you as second author. Cheers, Ralf diff --git a/tests/exceptions.at b/tests/exceptions.at index d551cb8..920b30e 100644 --- a/tests/exceptions.at +++ b/tests/exceptions.at @@ -29,7 +29,19 @@ AT_KEYWORDS([libltdl]) CPPFLAGS="$LTDLINCL $CPPFLAGS" AT_DATA([module.h], -[[class modexc { }; +[[#include <exception> +#include <string> +class modexc : public std::exception { +public: + modexc (std::string str) : message (str) { } + ~modexc () throw () { } + virtual const char *what () const throw () + { + return message.c_str (); + } +private: + std::string message; +}; extern "C" int modfoo () throw (modexc); ]]) @@ -39,7 +51,7 @@ AT_DATA([module.cpp], int modbar (void) throw (modexc) { - throw modexc (); + throw modexc ("exception in module"); } extern "C" @@ -48,16 +60,28 @@ int modfoo (void) throw (modexc) try { modbar (); } - catch (modexc) { - std::cerr << "caught inside module\n"; - throw modexc (); + catch (modexc e) { + std::cerr << "caught inside module: " << e.what () << '\n'; + throw modexc ("exception from module"); } return 0; } ]]) AT_DATA([lib.h], -[[class libexc { }; +[[#include <exception> +#include <string> +class libexc : public std::exception { +public: + libexc (std::string str) : message (str) { } + ~libexc () throw () { } + virtual const char *what () const throw () + { + return message.c_str (); + } +private: + std::string message; +}; int libfoo () throw (libexc); ]]) @@ -67,7 +91,7 @@ AT_DATA([lib.cpp], int libbar (void) throw (libexc) { - throw libexc (); + throw libexc ("exception in library"); } int libfoo (void) throw (libexc) @@ -75,9 +99,9 @@ int libfoo (void) throw (libexc) try { libbar (); } - catch (libexc) { - std::cerr << "caught inside lib\n"; - throw libexc (); + catch (libexc e) { + std::cerr << "caught inside lib: " << e.what () << '\n'; + throw libexc ("exception from library"); } return 0; } @@ -87,14 +111,26 @@ AT_DATA([main.cpp], [[#include <ltdl.h> #include <cstdlib> #include <iostream> +#include <exception> +#include <string> #include "lib.h" #include "module.h" -class exc { }; +class exc : public std::exception { +public: + exc (std::string str) : message (str) { } + ~exc () throw () { } + virtual const char *what () const throw () + { + return message.c_str (); + } +private: + std::string message; +}; int foo (void) throw (exc) { - throw exc (); + throw exc ("exception in program"); return 0; } @@ -104,8 +140,8 @@ int exceptions_in_prog (void) try { foo (); } - catch (exc) { - std::cerr << "caught\n"; + catch (exc e) { + std::cerr << "caught: " << e.what () << '\n'; return 0; } return 1; @@ -117,8 +153,8 @@ int exceptions_in_lib (void) try { libfoo (); } - catch (libexc) { - std::cerr << "caught\n"; + catch (libexc e) { + std::cerr << "caught: " << e.what () << '\n'; return 0; } return 1; @@ -161,7 +197,8 @@ int exceptions_in_module (void) try { (*pf) (); } - catch (modexc) { + catch (modexc e) { + std::cerr << "caught: " << e.what () << '\n'; if (lt_dlclose (handle)) { std::cerr << "dlclose failed: " << lt_dlerror () << '\n';