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
Created attachment 7277 [details] preprocessed source
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 ); }
: Search converges between 2004-09-27-014001-trunk (#563) and 2004-09-27-161002-trunk (#564).
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.
Related to bug 17801 which was caused by the same patch.
Doesn't koenig lookup apply? That'll pull in ::parseFontName because of ::QString
I don't know but Comeau C++ online tester accepts the code.
ah, [3.4.2]/2a says koenig is not done when regular lookup finds a member fn. Forgot that bit.
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.
Why shouldn't unqualified (not koenig) lookup find both versions of bar(), then?
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.
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 ().
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
*** Bug 17801 has been marked as a duplicate of this bug. ***
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.
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
Fixed in GCC 3.4.3 and GCC 4.0.0.
*** Bug 17904 has been marked as a duplicate of this bug. ***