Pointer-to-member-function as template parameter - strange error, plus an ICE
- From: Imre <imre42@xxxxxxxx>
- Date: 8 May 2007 13:01:41 -0700
Hi
Here's some code that makes the VC8 compiler do interesting things.
(In it's current form it doesn't really makes sense, I tried to strip
it down to the smallest possible code that still exhibits this
behavior.)
#include "stdafx.h"
template <class C, typename Sig>
struct Func;
template <class C, typename R, typename P1>
struct Func<C, R (P1)>
{
template <R (C::*)(P1)>
struct N;
};
template <class C, typename Sig>
struct F
{
template <class T>
static char Test(typename Func<C, Sig>::template N<&T::F>*);
};
template <class C, typename Sig>
struct G
{
typedef typename Func<C, Sig>::template N<&C::G> TD;
};
struct S
{
void G(int i) { }
int F(int i) { return 2; }
};
int _tmain(int argc, _TCHAR* argv[])
{
F<S, void (int)> h1; // 1
F<S, int (double)> h2; // 2
G<S, void (int)> h3; // 3
return 0;
}
This won't compile, saying that
error C2440: 'specialization' : cannot convert from 'overloaded-
function' to 'int (__thiscall S::* )(double)'
The error is in the typedef line, instantiated from the line marked
with 3.
The interesting thing is that that line uses the G template, which
only references the G() function in S. Where does the double argument
come from in the error message? Also, the message talks about an
overloaded function, but S::G() is not overloaded.
Some other interesting observations:
- If I delete any one of the 3 marked line in main(), then it
compiles
- If 1 is moved after 3, then it compiles
- If 2 is moved after 3, then it causes an Internal Compiler Error
Am I doing something wrong, or is it some kind of compiler bug?
Imre
.
- Follow-Ups:
- Re: Pointer-to-member-function as template parameter - strange error, plus an ICE
- From: Carl Daniel [VC++ MVP]
- Re: Pointer-to-member-function as template parameter - strange error, plus an ICE
- Prev by Date: Re: Launching an executable
- Next by Date: Re: facing a problem with vc++ list control (image list)
- Previous by thread: Launching an executable
- Next by thread: Re: Pointer-to-member-function as template parameter - strange error, plus an ICE
- Index(es):
Relevant Pages
|