Bug 17829 - [3.4 Regression] wrong error: call of overloaded function is ambiguous
Summary: [3.4 Regression] wrong error: call of overloaded function is ambiguous
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 3.4.3
Assignee: Nathan Sidwell
URL:
Keywords: ice-on-valid-code, rejects-valid
: 17801 17904 (view as bug list)
Depends on:
Blocks: 17801
  Show dependency treegraph
 
Reported: 2004-10-04 12:04 UTC by Michael Cieslinski
Modified: 2004-10-09 14:38 UTC (History)
4 users (show)

See Also:
Host: powerpc-linux-gnu
Target: powerpc-linux-gnu
Build: powerpc-linux-gnu
Known to work: 3.4.2 4.0.0
Known to fail: 3.4.3
Last reconfirmed: 2004-10-04 12:39:52


Attachments
preprocessed source (161.76 KB, text/plain)
2004-10-04 12:06 UTC, Michael Cieslinski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Cieslinski 2004-10-04 12:05:00 UTC
With snapshot gcc-4.0-20041003 I get an error (see below):
    "call of overloaded is ambiguous"
while only one function definition is present.
With gcc33, gcc34 and the previous snapshot gcc-4.0-20040926 this program 
compiles without error.

Michael Cieslinski

src.ii: In static member function `static QFontEngine* QFontDatabase::findFont
(QFont::Script, const QFontPrivate*, const QFontDef&, int)':
src.ii:48587: error: call of overloaded `parseFontName(const QString&, 
QString&, QString&)' is ambiguous
src.ii:28700: note: candidates are: static void QFontDatabase::parseFontName
(const QString&, QString&, QString&)
src.ii:48571: note:                 void parseFontName(const QString&, 
QString&, QString&)


g++40 -c -O2 -o out.o src.ii -v
Reading specs from /usr/local/gcc40/lib/gcc/powerpc-unknown-linux-
gnu/4.0.0/specs
Configured with: ../gcc40/configure --prefix=/usr/local/gcc40 --program-
suffix=40 --with-cpu=G5 --enable-altivec --enable-languages=c,c++ --enable-
checking
Thread model: posix
gcc version 4.0.0 20041003 (experimental)
 /usr/local/gcc40/libexec/gcc/powerpc-unknown-linux-gnu/4.0.0/cc1plus -
fpreprocessed src.ii -quiet -dumpbase src.ii -mcpu=G5 -auxbase-strip out.o -O2 -
version -o /tmp/ccd0gsRe.s
GNU C++ version 4.0.0 20041003 (experimental) (powerpc-unknown-linux-gnu)
        compiled by GNU C version 4.0.0 20041003 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
 as -mpower4 -maltivec -many -V -Qy -o out.o /tmp/ccd0gsRe.s
GNU assembler version 2.15.90 (ppc-redhat-linux) using BFD version 2.15.90 
20040225
Comment 1 Michael Cieslinski 2004-10-04 12:06:35 UTC
Created attachment 7277 [details]
preprocessed source
Comment 2 Andrew Pinski 2004-10-04 12:35:52 UTC
Reduced to:
class QString {};

class QFontDatabase
{
    static void findFont();
    static void parseFontName(const QString &name, QString &foundry, QString &family);
};  
    
static void parseFontName(const QString &name, QString &foundry, QString &family){}
    
void QFontDatabase::findFont( )
{   
    QString family_name, foundry_name, family;
    parseFontName( family, foundry_name, family_name );
}
Comment 3 Andrew Pinski 2004-10-04 12:36:08 UTC
: Search converges between 2004-09-27-014001-trunk (#563) and 2004-09-27-161002-trunk 
(#564).

Comment 4 Andrew Pinski 2004-10-04 12:39:51 UTC
Note if I change QString to be just an int, we accept the code.

Confirmed, we should find the class version as we do with changing QString to be an int.
Comment 5 Andrew Pinski 2004-10-04 12:43:07 UTC
Related to bug 17801 which was caused by the same patch.
Comment 6 Nathan Sidwell 2004-10-04 12:44:38 UTC
Doesn't koenig lookup apply?  That'll pull in ::parseFontName because of
::QString
Comment 7 Andrew Pinski 2004-10-04 12:46:48 UTC
I don't know but Comeau C++ online tester accepts the code.
Comment 8 Nathan Sidwell 2004-10-04 15:12:48 UTC
ah, [3.4.2]/2a says koenig is not done when regular lookup finds a member fn.
Forgot that bit.
Comment 9 Wolfgang Bangerth 2004-10-04 17:11:45 UTC
Confirmed indeed. Here's a testcase in our usual style: 
--------------------- 
struct A {}; 
 
struct B { 
    static void foo(); 
    static void bar(const A &); 
};   
     
void bar(const A &){} 
     
void B::foo () {    
    A a; 
    bar (a); 
} 
------------------------------ 
 
g/x> /home/bangerth/bin/gcc-3.3*/bin/c++ -c x.cc 
g/x> /home/bangerth/bin/gcc-3.4*/bin/c++ -c x.cc 
x.cc: In static member function `static void B::foo()': 
x.cc:12: error: call of overloaded `bar(A&)' is ambiguous 
x.cc:5: note: candidates are: static void B::bar(const A&) 
x.cc:8: note:                 void bar(const A&) 
 
Koenig lookup should definitely _not_ find the static member since 
it only looks up in the _namespace_ of an argument, but shouldn't 
consider class scopes of arguments. 
 
W. 
Comment 10 Giovanni Bajo 2004-10-05 01:17:33 UTC
Why shouldn't unqualified (not koenig) lookup find both versions of bar(), then?
Comment 11 Wolfgang Bangerth 2004-10-05 13:05:48 UTC
Well, yea, Nathan got me on the wrong track when mentioning Koenig. 
Koenig has nothing to do at all with the present problem. I simply 
forgot to realize that the call is from within a member function, 
not a global function. 
 
I don't have the right section of the standard ready, but all my instincts 
tell me that the call in the example is not ambiguous, but should quite 
unambiguously find the member function only. Note that the standard 
specifically says that the search for candidates ends if one or several 
are found in one scope from within the hierarchy of scopes that are 
searched  sequentially. I would guess that the class scope is the first 
one to look at. 
 
W. 
Comment 12 Nathan Sidwell 2004-10-05 16:05:15 UTC
2004-10-05  Nathan Sidwell  <nathan@codesourcery.com>

        PR c++/17829
        * parser.c (cp_parser_postfix_expression): Inhibit Koenig when
        unqualified lookup finds a member function.

we were doing koenig lookup when we shouldn't have been.  Which is why
changing the arg type from ::Qstring to int made it work -- that
changed the set of associated namespaces from (::) to ().
Comment 13 CVS Commits 2004-10-05 16:08:09 UTC
Subject: Bug 17829

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	nathan@gcc.gnu.org	2004-10-05 16:08:03

Modified files:
	gcc/cp         : ChangeLog parser.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/lookup: koenig4.C 

Log message:
	cp:
	PR c++/17829
	* parser.c (cp_parser_postfix_expression): Inhibit Koenig when
	unqualified lookup finds a member function.
	testsuite:
	PR c++/17829
	* g++.dg/lookup/koenig4.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4405&r2=1.4406
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.259&r2=1.260
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4386&r2=1.4387
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/koenig4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 14 Nathan Sidwell 2004-10-06 15:26:27 UTC
*** Bug 17801 has been marked as a duplicate of this bug. ***
Comment 15 Jakub Jelinek 2004-10-07 10:52:28 UTC
Nathan, are you going to apply this to gcc-3_4-branch as well?
It doesn't apply cleanly because of whitespace changes, but that's it.
I've bootstrapped/regtested it on {i386,ppc,ppc64,s390,s390x}-redhat-linux,
no regressions.
Comment 16 CVS Commits 2004-10-08 15:20:05 UTC
Subject: Bug 17829

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	nathan@gcc.gnu.org	2004-10-08 15:19:57

Modified files:
	gcc/cp         : ChangeLog parser.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/lookup: koenig4.C 

Log message:
	cp:
	PR c++/17829
	* parser.c (cp_parser_postfix_expression): Inhibit Koenig when
	unqualified lookup finds a member function.
	testsuite:
	PR c++/17829
	* g++.dg/lookup/koenig4.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.162&r2=1.3892.2.163
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.157.2.41&r2=1.157.2.42
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.279&r2=1.3389.2.280
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/koenig4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1

Comment 17 Giovanni Bajo 2004-10-08 17:43:33 UTC
Fixed in GCC 3.4.3 and GCC 4.0.0.
Comment 18 Andrew Pinski 2004-10-09 14:38:24 UTC
*** Bug 17904 has been marked as a duplicate of this bug. ***