Bug 35387 - __PRETTY_FUNCTION__ produces inconsistent output
Summary: __PRETTY_FUNCTION__ produces inconsistent output
Status: RESOLVED DUPLICATE of bug 99
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.1
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2008-02-27 08:51 UTC by Daniel Frey
Modified: 2008-02-28 17:07 UTC (History)
9 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-02-27 13:00:51


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Frey 2008-02-27 08:51:46 UTC
Minimal example program:

#include <iostream>
#include <algorithm>

template< typename T > struct A;

template< typename T, typename U > struct A< std::pair< T, U > >
{
  static void f()
  {
    std::cout << __PRETTY_FUNCTION__ << std::endl;
  }
};

int main()
{
  A< std::pair< int, int > >::f();
}


Output of __PRETTY_FUNCTION__ from this program:

static void A<std::pair<_T1, _T2> >::f() [with T = int, U = int]

Problem:

_T1 and _T2 are printed as the pair's parameter names, but it then say T=int and U=int.

Additional information:

This only seems to occur with partial specialization.
Comment 1 Richard Biener 2008-02-27 09:35:06 UTC
It uses the names as in the std::pair template declaration, so you could argue
this is correct.
Comment 2 Daniel Frey 2008-02-27 12:02:50 UTC
I understand where the names come from, but that doesn't make the message correct. Consider the specialization in the example program to use <_T2,_T1> (note the reversed order) and an instantiation with <int,double>, the resulting message is:

static void A<std::pair<_T1, _T2> >::f() [with _T2 = int, _T1 = double]

which is *really* misleading. Since it's actually vice versa.

Additionally I just found out that the same problem also occurs within error and warning messages from the compiler, so it's not limited to __PRETTY_FUNCTION__. I triggered a warning for an unused variable, which reads:

foo.cpp: In static member function ‘static void A<std::pair<_T1, _T2> >::f() [with T = int, U = int]’:
foo.cpp:17:   instantiated from here
foo.cpp:10: warning: unused variable ‘i’

Regards, Daniel
Comment 3 Manuel López-Ibáñez 2008-02-27 13:00:51 UTC
Confirmed. This is a diagnostics bug. (And perhaps a duplicate).

Thanks for the report. If you would like to contribute a patch, please read 
http://gcc.gnu.org/contribute.html
Comment 4 Daniel Frey 2008-02-27 21:58:59 UTC
More information:

I checked out the trunk and checked it again. The bug is still present, but while testing it, I noticed that the problem does not occur with my own types, only with types from the standard library. Here's the code I used:

#include <algorithm>

template< typename X, typename Y > struct P {};

template< typename > struct A;

template< typename T, typename U >
struct A< P< T, U > >
{ static void f() { int i; } };

template< typename V, typename W >
struct A< std::pair< V, W > >
{ static void f() { int i; } };

int main()
{
  A< P< int, double > >::f();
  A< std::pair< int, double > >::f();
}

and the output is:

frey@fiasko:~/work/test/foo$ /home/frey/work/svn/gcc/host-i686-pc-linux-gnu/gcc/g++ -B/home/frey/work/svn/gcc/host-i686-pc-linux-gnu/gcc/ -ansi -pedantic -Wall -Wextra  -I/home/frey/work/svn/gcc/i686-pc-linux-gnu/libstdc++-v3/include/i686-pc-linux-gnu -I/home/frey/work/svn/gcc/i686-pc-linux-gnu/libstdc++-v3/include -I/home/frey/work/svn/gcc/libstdc++-v3/libsupc++ foo.cpp -c -o foo
foo.cpp: In static member function ‘static void A<P<T, U> >::f() [with T = int, U = double]’:
foo.cpp:12:   instantiated from here
foo.cpp:7: warning: unused variable ‘i’
foo.cpp: In static member function ‘static void A<std::pair<_T1, _T2> >::f() [with V = int, W = double]’:
foo.cpp:13:   instantiated from here
foo.cpp:8: warning: unused variable ‘i’
frey@fiasko:~/work/test/foo$ /home/frey/work/svn/gcc/host-i686-pc-linux-gnu/gcc/g++ --version
g++ (GCC) 4.4.0 20080227 (experimental)
[snip]
Comment 5 Andrew Pinski 2008-02-27 22:45:34 UTC
This is most likely a dup of bug 99.
Comment 6 Daniel Frey 2008-02-28 08:14:49 UTC
I looked at bug #99, but I am unsure whether this bug is really a dup of it. #99 is about overloads and occurs with user types, while this bug is about partial template specializations and occurs only with certain types from the STL.
Comment 7 Andrew Pinski 2008-02-28 17:07:55 UTC
No, bug 99 has specialization too:

 template<unsigned int n, unsigned int m>
   double ch(dummy<n>, dummy<m>);

 template<unsigned int n>
   double ch(dummy<n>, dummy<0>);

 template<unsigned int m>
   double ch(dummy<0>, dummy<m>);

Those are all specialization of the first one, not overloaded functions.

See also comment #11.

*** This bug has been marked as a duplicate of 99 ***