C++ function pointer weirdness

2005-02-22 Thread Volker Reichelt
Yesterday the output of the following program changed
(probably due to the fix for PR19076):

==
template typename T int ref (T){ return 0; }
template typename T int ref (const T)  { return 1; }
template typename T int ref (const volatile T) { return 2; }
template typename T int ref (volatile T)   { return 4; }

template typename T int ptr (T*){ return 0; }
template typename T int ptr (const T*)  { return 8; }
template typename T int ptr (const volatile T*) { return 16; }
template typename T int ptr (volatile T*)   { return 32; }

void foo() {}

int main()
{
return ref(foo) + ptr(foo);
}
==

GCC 2.95.3 - 3.4.0 return 0, GCC 3.4.1 - 3.4.4-20050222 return 2,
and now mainline again returns 0.

So the question is: What is the correct return value?

Btw, we really should have this in the testsuite.

In any case, we have a wrong-code regression here, either on the
3.4 branch or on mainline. But before I open a PR I'd like to sort
out which is the correct behavior.

When the result changed in 3.4.1 I bugged Nathan (who caused this
change) about it, and he claimed that '2' is the correct result.
Intel's compiler indeed returns 2.

Regards,
Volker




Re: C++ function pointer weirdness

2005-02-22 Thread Gabriel Dos Reis
Volker Reichelt [EMAIL PROTECTED] writes:

| Yesterday the output of the following program changed
| (probably due to the fix for PR19076):

Thanks for raising this issue.

| 
| ==
| template typename T int ref (T){ return 0; }
| template typename T int ref (const T)  { return 1; }
| template typename T int ref (const volatile T) { return 2; }
| template typename T int ref (volatile T)   { return 4; }
| 
| template typename T int ptr (T*){ return 0; }
| template typename T int ptr (const T*)  { return 8; }
| template typename T int ptr (const volatile T*) { return 16; }
| template typename T int ptr (volatile T*)   { return 32; }
| 
| void foo() {}
| 
| int main()
| {
| return ref(foo) + ptr(foo);
| }
| ==
| 
| GCC 2.95.3 - 3.4.0 return 0, GCC 3.4.1 - 3.4.4-20050222 return 2,
| and now mainline again returns 0.

I would say that is the behaviour I would expect.  I don't understand
the answer 2.  I'll check with the C++ Core Working Group.

| So the question is: What is the correct return value?
| 
| Btw, we really should have this in the testsuite.
| 
| In any case, we have a wrong-code regression here, either on the
| 3.4 branch or on mainline. But before I open a PR I'd like to sort
| out which is the correct behavior.
| 
| When the result changed in 3.4.1 I bugged Nathan (who caused this
| change) about it, and he claimed that '2' is the correct result.
| Intel's compiler indeed returns 2.

Well, I definitely needs an answer better than that is what Intel's
compiler does :-)

-- Gaby