Bug 20966 - [DR 503] cv-qualified function references and overload resolution
Summary: [DR 503] cv-qualified function references and overload resolution
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on: 28385
Blocks:
  Show dependency treegraph
 
Reported: 2005-04-12 11:10 UTC by Volker Reichelt
Modified: 2010-01-13 18:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.2.0 4.3.0 4.4.1 4.5.0
Known to fail:
Last reconfirmed: 2005-12-30 07:04:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2005-04-12 11:10:39 UTC
Consider the following program:

====================================================================
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 through 3.4.0 return 0, GCC 3.4.1 through 3.4.3 return 2.
But the 4.0 branch and mainline again return 0.

The current reading of the standard suggests that 2 is indeed the correct
answer (quoting Gaby: In summary, cv-qualifiers although ignored and void
of semantics for function types, do actually play a significant role in
"winning" the partial ordering tournoi, and after that disappear.)

Hence, we have a wrong-code bug in 4.0 branch and mainline.

However, since the situation between pointers and references is unsymmetric
in this case, Gaby is going to raise the issue in the core language list.

So, I'm suspending this until we have a definite answer.

See also http://gcc.gnu.org/ml/gcc/2005-02/msg00834.html
Comment 1 Gabriel Dos Reis 2005-04-12 11:27:53 UTC
Subject: Re:  New: [4.0/4.1 regression] cv-qualified function references and overload resolution

"reichelt at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes:

| However, since the situation between pointers and references is unsymmetric
| in this case, Gaby is going to raise the issue in the core language list.

I just spoke to John Spicer before lunch, and he told me there is an
open issue for that.  I'll give you the number as soon as he gave it
to me.

-- Gaby
Comment 2 Volker Reichelt 2005-06-10 08:55:36 UTC
It's DR 503.
Comment 3 Volker Reichelt 2006-08-17 13:06:19 UTC
The fix of PR 28385 changed the behavior on mainline so that the bug
is now fixed on mainline (w.r.t. current version of the standard).

I.e. only the 4.0 branch and the 4.1 branch (and everyting before 3.4.1)
is affected.
Comment 4 Paolo Carlini 2010-01-13 18:07:56 UTC
This is ok in the current release branches.