This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

PATCH: fix __func__ for C++ destructors


As discussed earlier on gcc@gcc.gnu.org: __func__ returns a short string, without scope or type information, containing the name of the current function. Inside a C++ destructor foo::~foo(), it returns "foo", not "~foo". Users consider this a bug. I have to agree. It's counterintuitive, and nothing in our documentation suggests that it should do this.

(Note that this is a GNU extension. __func__ is part of standard C, but not standard C++.)

The problem is in c-common.c, in fname_as_string. It thinks that the contents of DECL_NAME is an acceptable human-readable string. Sometimes that assumption is right, sometimes it isn't. The right way to get a short human-readable string is to use *lang_hooks.decl_printable_name with verbosity 0.

This patch does that. ChangeLog entries and three new test cases are included. I've verified that the patch doesn't break the bootstrap, and that it's only impact on test status is that it makes one of my new tests succeed where it used to fail.

OK to commit to mainline?

--Matt

P.S. Just out of curiosity, I also checked the behavior of even more esoteric C++ member functions. A user-defined conversion operator that shows up as "operator Pv" before my patch shows up as "operator void*" afterwards. I think this is an improvement. I also think it's too esoteric to be worth writing a fourth test case for.

Attachment: fnname.txt
Description: Text document



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