The program below is supposed to output f(char) f(int) f(char) f(char) according to 14.6p9. gcc (all of 2.95.3, pre-3.0, and 3.1 20010518) outputs f(int) f(int) f(int) f(char) Release: gcc version 3.0 20010521 (prerelease) Environment: Linux 2.2.4 with glibc 2.2.3 How-To-Repeat: // example (slightly adapted) from 14.6p9 #include <iostream> void f(char) { std::cout << "f(char)" << std::endl; } template<class T> void g(T t) { f(1); // not dependent f(t); // dependent } void f(int) { std::cout << "f(int)" << std::endl; } int main() { g(2); // f(char) followed by f(int) g('a'); // two f(char) }
From: Martin Sebor <sebor@roguewave.com> To: Jens.Maurer@gmx.net Cc: gcc-gnats@gcc.gnu.org Subject: Re: c++/2922: two-phase name lookup not working Date: Thu, 24 May 2001 15:47:15 -0600 Jens.Maurer@gmx.net wrote: > > >Number: 2922 > >Category: c++ > >Synopsis: two-phase name lookup not working > >Confidential: no > >Severity: serious > >Priority: medium > >Responsible: unassigned > >State: open > >Class: wrong-code > >Submitter-Id: net > >Arrival-Date: Thu May 24 02:06:01 PDT 2001 > >Closed-Date: > >Last-Modified: > >Originator: Jens Maurer > >Release: gcc version 3.0 20010521 (prerelease) > >Organization: > >Environment: > Linux 2.2.4 with glibc 2.2.3 > >Description: > The program below is supposed to output > f(char) > f(int) > f(char) > f(char) > > according to 14.6p9. But take a look at issue 197 at http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#197 Not that the issue makes gcc's behavior correct (f(char) should apparently be called in all 4 cases). Regards Martin > > gcc (all of 2.95.3, pre-3.0, and 3.1 20010518) outputs > f(int) > f(int) > f(int) > f(char) > >How-To-Repeat: > > // example (slightly adapted) from 14.6p9 > > #include <iostream> > > void f(char) > { > std::cout << "f(char)" << std::endl; > } > > template<class T> > void g(T t) > { > f(1); // not dependent > f(t); // dependent > } > > void f(int) > { > std::cout << "f(int)" << std::endl; > } > > int main() > { > g(2); // f(char) followed by f(int) > g('a'); // two f(char) > } > > >Fix: > > >Release-Note: > >Audit-Trail: > >Unformatted:
From: Jens Maurer <Jens.Maurer@gmx.net> To: Martin Sebor <sebor@roguewave.com> Cc: gcc-gnats@gcc.gnu.org Subject: Re: c++/2922: two-phase name lookup not working Date: Fri, 25 May 2001 00:44:56 +0200 Martin Sebor wrote: > Jens.Maurer@gmx.net wrote: > > The program below is supposed to output > > f(char) > > f(int) > > f(char) > > f(char) You're correct, core issue 197 says it should output "f(char)" in all cases. Jens Maurer
State-Changed-From-To: open->suspended State-Changed-Why: we know. will be dealt with in the parser rewrite.
From: nathan@gcc.gnu.org To: Jens.Maurer@gmx.net, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: c++/2922 Date: 27 May 2001 16:28:04 -0000 Synopsis: two-phase name lookup not working State-Changed-From-To: open->suspended State-Changed-By: nathan State-Changed-When: Sun May 27 09:28:04 2001 State-Changed-Why: we know. will be dealt with in the parser rewrite. http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2922&database=gcc
State-Changed-From-To: suspended->analyzed State-Changed-Why: New parser gives: f(char) f(int) f(char) f(char) which is better but we still have one f(int), which I understand is wrong according to the DR referenced above.
I'm testing a patch for this.
For reference, the problem is that for unqualified function calls with type- dependent arguments, we should: 1) do a normal unqualified lookup at parsing time, and preserve the result, which is an overload set. (will be done in cp_parser_postfix_expression, case CPP_OPEN_PAREN). 2) perform a koenig lookup at instantiation time, merging its result with the previous set. (done in tsusbt_copy_and_build, case CALL_EXPR). 3) do overload resolution, etc. Instead, what happens currently is that both kind of lookups are deferred till instantiation time. I'm fixing this, but it is not trivial because I'm doing cleanups as I go.
*** Bug 13812 has been marked as a duplicate of this bug. ***
*** Bug 11296 has been marked as a duplicate of this bug. ***
Not working on this anymore. Andrew closed PR 11296 as a dup of this, but I'm not 100% sure. This is the testcase, so that it can be tested and added to the testsuite: ----------------------------------------------------- namespace N { template <class T> T foo (T) { return T (); } template <class T> T bar (T t) { return foo (t); } } struct S { S (int i = 0): i_ (i) { } int i_; }; namespace N { /* template <> */ S foo (S) { return S (1); } } int main () { return 1 == N::bar (S ()).i_; } ----------------------------------------------------- (should return 0, but returns 1).
(In reply to comment #10) > Not working on this anymore. Andrew closed PR 11296 as a dup of this, but I'm > not 100% sure. This is the testcase, so that it can be tested and added to the > testsuite: > > ----------------------------------------------------- > namespace N { > template <class T> T foo (T) { return T (); } > template <class T> T bar (T t) { return foo (t); } > } > > struct S { S (int i = 0): i_ (i) { } int i_; }; > > namespace N { > /* template <> */ S foo (S) { return S (1); } > } > > int main () > { > return 1 == N::bar (S ()).i_; > } > ----------------------------------------------------- > (should return 0, but returns 1). > Here is another test case that does compile time two-phase name check. Comeau online 4.3.3 BETA August 4, 2003 passes it, gcc 3.4.3 fails. For discussion please see http://groups-beta.google.com/group/comp.lang.c++. moderated/msg/c7227abb97603d15?hl=en namespace tpl_ { template<class T> char test(T); template<class T> struct check { static T const t; enum { value = 1 == sizeof(test(t)) }; }; double test(int); } bool const two_phase_lookup_supported = tpl_::check<int>::value; int compile_time_assert[two_phase_lookup_supported ? 1 : -1];
Subject: Bug 2922 CVSROOT: /cvs/gcc Module name: gcc Changes by: dgregor@gcc.gnu.org 2005-07-21 03:53:08 Modified files: gcc/cp : ChangeLog name-lookup.c semantics.c Log message: 2005-07-20 Douglas Gregor <doug.gregor@gmail.com> PR c++/2922 * semantics.c (perform_koenig_lookup): For dependent calls, just return the set of functions we've found so far. Later, it will be augmented by those found through argument-dependent lookup. * name-lookup.c (lookup_arg_dependent): Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4826&r2=1.4827 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.129&r2=1.130 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.481&r2=1.482
Subject: Bug 2922 CVSROOT: /cvs/gcc Module name: gcc Changes by: dgregor@gcc.gnu.org 2005-07-21 03:56:46 Modified files: gcc/testsuite : ChangeLog gcc/testsuite/g++.dg/template: call3.C crash37.C ptrmem4.C gcc/testsuite/g++.old-deja/g++.other: pmf3.C Added files: gcc/testsuite/g++.dg/lookup: two-stage2.C two-stage3.C two-stage4.C Log message: 2005-07-20 Douglas Gregor <doug.gregor@gmail.com> PR c++/2922 * g++.dg/lookup/two-stage2.C: New. * g++.dg/lookup/two-stage3.C: New. * g++.dg/lookup/two-stage4.C: New. Illustrates how we have not yet fixed two-stage name lookup for operators. * g++.dg/template/call3.C: Compiler now produces an appropriate error message. * g++.dg/template/crash37.C: Compiler now describes bla() on line 14 as a candidate. * g++.dg/template/ptrmem4.C: Compiler produces different error message. * g++.old-deja/g++.other/pmf3.C: Compiler now describes connect_to_method as a candidate. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5789&r2=1.5790 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/two-stage2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/two-stage3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/two-stage4.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/call3.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/crash37.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/ptrmem4.C.diff?cvsroot=gcc&r1=1.2&r2=1.3 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.other/pmf3.C.diff?cvsroot=gcc&r1=1.3&r2=1.4
Fixed.
Subject: Bug 2922 CVSROOT: /cvs/gcc Module name: gcc Changes by: dgregor@gcc.gnu.org 2005-07-21 14:18:54 Modified files: gcc/cp : ChangeLog Log message: Completed this ChangeLog entry: 2005-07-20 Douglas Gregor <doug.gregor@gmail.com> PR c++/2922 * semantics.c (perform_koenig_lookup): For dependent calls, just return the set of functions we've found so far. Later, it will be augmented by those found through argument-dependent lookup. * name-lookup.c (lookup_arg_dependent): Implement DR 164 by removing the optimization that skips namespaces where the functions were originally found. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4828&r2=1.4829
Subject: Bug 2922 CVSROOT: /cvs/gcc Module name: gcc Changes by: dgregor@gcc.gnu.org 2005-07-21 15:14:59 Modified files: gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/lookup: two-stage5.C Log message: 2005-07-21 Douglas Gregor <doug.gregor@gmail.com> PR c++/2922 * g++.dg/lookup/two-stage5.C: New test from bug comments. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5796&r2=1.5797 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/two-stage5.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
(In reply to comment #13) ... > * g++.dg/lookup/two-stage2.C: New. FWIW, the following comment in this patch is wrong: + g(2); // f(char) followed by f(int) ^^^^^^^^^^^^^^^^^^ The call to g<int>(2) should cause 2 calls to f(char).
*** Bug 23724 has been marked as a duplicate of this bug. ***
*** Bug 25278 has been marked as a duplicate of this bug. ***
*** Bug 25495 has been marked as a duplicate of this bug. ***
*** Bug 24795 has been marked as a duplicate of this bug. ***
*** Bug 26079 has been marked as a duplicate of this bug. ***
*** Bug 26311 has been marked as a duplicate of this bug. ***
*** Bug 28631 has been marked as a duplicate of this bug. ***
*** Bug 29229 has been marked as a duplicate of this bug. ***
*** Bug 30059 has been marked as a duplicate of this bug. ***
*** Bug 30232 has been marked as a duplicate of this bug. ***
*** Bug 32440 has been marked as a duplicate of this bug. ***
*** Bug 260998 has been marked as a duplicate of this bug. *** Seen from the domain http://volichat.com Page where seen: http://volichat.com/adult-chat-rooms Marked for reference. Resolved as fixed @bugzilla.