This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] libstdc++/14493


On Jan 30, 2007, at 4:19 PM, Paolo Carlini wrote:

Hi Howard,

ABI concerns? Say a client that derived from bad_alloc and overloaded what()? Wouldn't his what() get corrupted (call the wrong what())? Other than that (and hope I'm wrong) I like this change.

thanks for asking, better be safe, this PR remained open so much time...


Anyway, are you considering a situation like compiling the following with a previous compiler:

#include <new>
#include <cstring>
#include <cassert>

struct my_bad_alloc
: std::bad_alloc
{
 virtual const char*
 what() const throw()
 { return "my_bad_alloc"; }
};

int main()
{
 my_bad_alloc mba;
 assert( !strcmp(mba.what(), "my_bad_alloc") );
}

and running it (linking it) vs the new .so? It runs fine.

Yes, that was my concern. I don't understand why it works, but I'm glad it does. Thanks for checking it out.


<paranoia>
Is gcc inlining the virtual?  As opposed to going through the vtable?

#include <new>
#include <cstring>
#include <cassert>

struct my_bad_alloc
: std::bad_alloc
{
 virtual const char*
 what() const throw();
};

int main()
{
 my_bad_alloc mba;
 assert( !strcmp(mba.what(), "my_bad_alloc") );
}

const char*
my_bad_alloc::what() const throw()
 { return "my_bad_alloc"; }

</paranoia>

-Howard


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]