[cfe-dev] clang and gcc implement __PRETTY_FUNCTION__ differently

Jean-Daniel Dupas devlists at shadowlab.org
Sun Dec 18 07:15:52 PST 2011


Le 18 déc. 2011 à 15:38, Nikola Smiljanic a écrit :

> Here's something I coded to try things out. Should we print function parameter types the way we do right now or should we do it like gcc (printing template parameter names instead of real type names)?
> 
> gcc:
> const char* foo(T) [with T = int] 
> 
> msvc:
> const char *__cdecl foo<int>(int)
> 
> clang:
> const char *foo(int)
> 
> clang + patch:
> const char* foo(int) [T = int]

This form is ambiguous. You don't know which argument use the template type.

For example, if foo were declared like that:
int foo(T x, int y);

you will get:
int foo(int x, int y) [T = int]


> potential formatting (gcc msvc hybrid):
> const char *foo<T = int>(T)
> 
> What do you think?
> 
> On Thu, Dec 1, 2011 at 4:07 PM, Douglas Gregor <dgregor at apple.com> wrote:
> 
> On Nov 30, 2011, at 9:03 PM, Eli Friedman wrote:
> 
> > 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.
> 
> 
> Right. For this reason, I like GCC's output better (except that the '*' is in the wrong place <g>).
> 
>        - Doug
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> 
> <pretty_function.patch>_______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-- Jean-Daniel




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111218/2ae77b3b/attachment.html>


More information about the cfe-dev mailing list