This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/7704: template match difference on function pointer template args
- From: leick dot robinson at motorola dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 23 Aug 2002 16:29:32 -0000
- Subject: c++/7704: template match difference on function pointer template args
- Reply-to: leick dot robinson at motorola dot com
>Number: 7704
>Category: c++
>Synopsis: template match difference on function pointer template args
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Aug 23 09:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: leick.robinson@motorola.com
>Release: gcc 2.95.2 or gcc 3.0.4
>Organization:
>Environment:
SUNW,Ultra-60
SunOS 5.8
>Description:
It's not clear whether the bug is in gcc 2.95.2 or 3.0.4.
There's a difference in the way these releases match
template arguments to the corresponding (partial) template
specialization.
In the code below, gcc 2.95.2 matches the function pointer
argument ( A<void (*) ()> ) to the last specialization
( class A<retval (*) (...)> ).
On the other hand, gcc 3.0.4 matches it to the specialization
for pointers ( A<U*> ).
Which is the correct behavior?
>How-To-Repeat:
#include <iostream>
using namespace std;
template <class T>
class A {
public:
static void foo()
{
cout << "Default A" << endl;
}
};
// Template specialization for a pointer
template <class U>
class A<U*> {
public:
static void foo()
{
cout << "A for pointers" << endl;
}
};
// Template specialization for function pointers (?)
template <class retval>
class A<retval (*) (...)> {
public:
static void foo()
{
cout << "A for function pointers" << endl;
};
};
int main()
{
A<int>::foo();
A<int*>::foo();
A<void (*) ()>::foo();
}
// g++ 2.95.2 produces:
//
// Default A
// A for pointers
// A for function pointers
//
// g++ 3.0.4 produces:
//
// Default A
// A for pointers
// A for pointers
//
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: