From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gabriel Dos Reis To: gdr@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: c++/3585: wrong function overload resolution? Date: Fri, 06 Jul 2001 06:56:00 -0000 Message-id: <20010706135601.17299.qmail@sourceware.cygnus.com> X-SW-Source: 2001-07/msg00159.html List-Id: The following reply was made to PR c++/3585; it has been noted by GNATS. From: Gabriel Dos Reis To: gawrilow@math.tu-berlin.de Cc: gcc-gnats@gcc.gnu.org Subject: Re: c++/3585: wrong function overload resolution? Date: 06 Jul 2001 15:49:45 +0200 gawrilow@math.tu-berlin.de writes: | >Number: 3585 | >Category: c++ | >Synopsis: wrong function overload resolution? | >Confidential: no | >Severity: serious | >Priority: medium | >Responsible: unassigned | >State: open | >Class: rejects-legal | >Submitter-Id: net | >Arrival-Date: Fri Jul 06 04:06:01 PDT 2001 | >Closed-Date: | >Last-Modified: | >Originator: Ewgenij Gawrilow | >Release: 3.0 | >Organization: | >Environment: | Sun UltraSPARC, Solaris 8 | >Description: | Let's consider the following fragment: | | void f(int& x) { } // #1 | | void f(int x) { } // #2 Nobody should be writing that :-) | int temp() { return 0; } | | int main() { | int var=0; | f(var); // should resolve to #1 On what basis? | f(temp()); // resolves to #2 | } | | The gcc rejects f(var) as ambiguous reasoning that #1 and #2 | were equally good. GCC is right in doing so. | IMHO, resolving to #2 includes an | lvalue-to-rvalue conversion, where #1 incurs an identity | conversion, thus being better. Am I missing something? identity and lvalue-to-rvalue conversion both have Exact Match rank. See Table 9. | Thus the final questions: who understands the overload | resolution rules better: gcc 3.0, gcc 2.95, GCC-3.0. | How could I otherwise distinct between rvalue and lvalue | arguments to an overloaded function, without using | f(const T&) ? You cannot because both lvalue-transformation and identity transformation have Exact Match rank. -- Gaby