[cfe-dev] clang and gcc implement __PRETTY_FUNCTION__ differently

Eli Friedman eli.friedman at gmail.com
Wed Nov 30 21:03:43 PST 2011


On Wed, Nov 30, 2011 at 8:45 PM, Joerg Sonnenberger
<joerg at britannica.bec.de> wrote:
> On Wed, Nov 30, 2011 at 06:21:04PM -0800, Kostya Serebryany wrote:
>> #include <stdio.h>
>> template<class T>
>> const char *foo() {
>>   return __PRETTY_FUNCTION__;
>> }
>> int main() {
>>   printf("%s\n", foo<int>());
>> }
>
> This gets more interesting if the template is actually used by the
> function. Changing it to foo(T x) and adjusting the call, the result is:
>
> clang:
> const char *foo(int)
>
> gcc:
> const char* foo(T) [with T = int]
>
> I don't think the GCC output is really better.

It's worth noting that clang's output is actually ambiguous in some
cases at the moment: you can't tell the difference between "void
f(int)" and "template<typename T> void f(T)" with T=int.

-Eli




More information about the cfe-dev mailing list