Strange issue regarding template functions, struct static members and g++

B

BigMan

Well... g++ 3.4.2 (mingw-special) won't compile the following code. It
says:

In function `void f2()':
error: cannot convert `int s::*' to `int*' for argument `1' to `void
f(int*)'

void f( int* )
{
}

struct s
{
static int i;
};

template< typename t >
void f2( )
{
f( &s::i ); // won't compile
}

void f3( )
{
f( &s::i ); // compiles fine
}

Who's wrong here? Is it the compiler or is it me?
 
M

Malte Starostik

BigMan said:
Well... g++ 3.4.2 (mingw-special) won't compile the following code. It
says:

In function `void f2()':
error: cannot convert `int s::*' to `int*' for argument `1' to `void
f(int*)'

void f( int* )
{
}

struct s
{
static int i;
};

template< typename t >
void f2( )
{
f( &s::i ); // won't compile
}

void f3( )
{
f( &s::i ); // compiles fine
}

Who's wrong here? Is it the compiler or is it me?

I'm rather sure it's the compiler, does anyone disagree?
Same here with mingw. This older version on my other box:
g++ (GCC) 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)
compiles it fine. The mingw version compiles it if I omit the & but I
didn't test whether the resulting program will also work. Either way,
ask in a gcc NG if this is a known regression or file a bug report
otherwise.

Cheers,
Malte
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top