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; }
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
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
Jason can you add the testcase to the testsuite and close this bug or is this needed open for another problem?
feexed