Bug 16334 - No warning about use of overloading extension
Summary: No warning about use of overloading extension
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P2 normal
Target Milestone: 4.0.0
Assignee: Jason Merrill
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-07-02 19:10 UTC by Mark Mitchell
Modified: 2004-07-10 00:26 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-07-07 22:06:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Mitchell 2004-07-02 19:10:33 UTC
G++ has an extension to the overloading rules of C++.  In particular, when ISO
C++ would consider a call ambiguous, G++ does an additional check.  It finds the
function whose *worst* conversion is least bad; if there is a unique such
function, that one is used.  (The code that does this is at the end of "joust".)

Jason indicated that this extension should not be removed due to backwards
compatibility issues, but that we should always be issuing a pedwarn in such cases.

However, if the winning candidate under the extension turns out to be a built-in
operator, no warning is issued.

Jason agreed to make sure that a warning is issued even in that case.  Perhaps
this message will also induce him into documenting this alleged feature in the
extensions portion of the manual. :-)

A test case follows.

extern "C" int printf(const char *, ...);
class MSBinaryVector {
public:
    MSBinaryVector (unsigned int, unsigned char =0)
    {
    }
};
MSBinaryVector operator& (const unsigned char, const MSBinaryVector
                          &){
    printf("not built-in\n");
    return 0;
}
typedef unsigned char __iostate;
enum io_state { eofbit };
int main() {
    __iostate state;
    return state & eofbit;
}
Comment 1 Jason Merrill 2004-07-07 21:02:09 UTC
Subject: Re:  New: No warning about use of overloading
 extension

On 2 Jul 2004 19:10:39 -0000, "mmitchel at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> wrote:

> Jason indicated that this extension should not be removed due to backwards
> compatibility issues

That's not exactly what I meant; I meant that an error that says "this is
ambiguous even though you might expect us to choose this candidate for this
reason" is better than an error that just says "ambiguous".

Patch forthcoming.

Jason
Comment 2 GCC Commits 2004-07-07 21:17:01 UTC
Subject: Bug 16334

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	jason@gcc.gnu.org	2004-07-07 21:16:58

Modified files:
	gcc/cp         : ChangeLog call.c 

Log message:
	PR c++/16334
	* call.c (build_new_op): Give overload warnings for built-in
	candidates.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4173&r2=1.4174
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.491&r2=1.492

Comment 3 Andrew Pinski 2004-07-07 22:23:07 UTC
Jason can you add the testcase to the testsuite and close this bug or is this needed open for another 
problem?
Comment 4 Jason Merrill 2004-07-08 20:52:15 UTC
feexed