Dear All, I am unable to understand following test case behaviour. When i compile and execute this with g++ 3.4.6 it works fine. But when i compile and execute this with g++ 4.3.2 it aborts. I think the test case is OK. But g++ 4.3.2 having bug. Below is test case: ========================================================== #define ieq(X,Y) if((X)!=(Y)) abort(); extern void abort (); struct B_ { int i; }; struct D_:public B_ { }; D_ d_; int f_ (B_ &) { return 100; } template < class T > int g_ (T t) { return f_ (d_) + f_ (t); } int f_ (D_ &) { return 1; } int main (int argc, char *argv[]) { D_ d; ieq (g_ (d), 101); return 0; } ========================================================== Please help me regarding this.
Confirmed. For the following neither f_ nor d_ are dependent and should be bound to f_ (B_ &) during first-stage name-lookup. For some reason this doesn't work - it does if d_ is of type B_ though. extern "C" void abort (); struct B_ { }; struct D_:public B_ { }; D_ d_; void f_ (B_ &) { } template < class T > void g_ (T t) { f_ (d_); } void f_ (D_ &) { abort (); } int main (int argc, char *argv[]) { D_ d; g_ (d); return 0; }
Even the following fails extern "C" void abort (); struct B_ { }; struct D_ : public B_ { }; D_ d_; void f_ (B_ &) { } template < class T > void g_ () { return f_ (d_); } int main () { g_<int> (); return 0; } void f_ (D_ &) { abort (); } where f_ (D_ &) must not be even in the 2nd stage name-lookup overload set.
We seem to not know if we bound f_ already. Instead another round of koenig lookup is applied from #0 perform_koenig_lookup (fn=0x7ffff6458500, args=0x7ffff6463480) at /space/rguenther/src/svn/trunk/gcc/cp/semantics.c:1797 #1 0x00000000004c9e14 in tsubst_copy_and_build (t=0x7ffff7ebd870, args=0x7ffff64631b0, complain=tf_warning_or_error, in_decl=0x7ffff6461780, function_p=0 '\0', integral_constant_expression_p=0 '\0') at /space/rguenther/src/svn/trunk/gcc/cp/pt.c:11293 #2 0x00000000004c6798 in tsubst_expr (t=0x7ffff7ebd870, args=0x7ffff64631b0, complain=tf_warning_or_error, in_decl=0x7ffff6461780, integral_constant_expression_p=0 '\0') at /space/rguenther/src/svn/trunk/gcc/cp/pt.c:10880 #3 0x00000000004bff18 in tsubst_expr (t=0x7ffff644a5c0, args=0x7ffff64631b0, complain=tf_warning_or_error, in_decl=0x7ffff6461780, integral_constant_expression_p=0 '\0') at /space/rguenther/src/svn/trunk/gcc/cp/pt.c:10483 #4 0x00000000004c1c98 in tsubst_expr (t=0x7ffff7ebd7d0, args=0x7ffff64631b0, complain=tf_warning_or_error, in_decl=0x7ffff6461780, integral_constant_expression_p=0 '\0') at /space/rguenther/src/svn/trunk/gcc/cp/pt.c:10630 #5 0x00000000004e78c5 in instantiate_decl (d=0x7ffff6458900, defer_ok=0, expl_inst_class_mem_p=0 '\0') at /space/rguenther/src/svn/trunk/gcc/cp/pt.c:15378 #6 0x00000000004e7f8c in instantiate_pending_templates (retries=0) at /space/rguenther/src/svn/trunk/gcc/cp/pt.c:15474 #7 0x0000000000540bb0 in cp_write_global_declarations () at /space/rguenther/src/svn/trunk/gcc/cp/decl2.c:3364 note the instantiation is from cp_write_global_declarations which is after the whole unit is parsed, which may explain comment #2.
*** Bug 38031 has been marked as a duplicate of this bug. ***
G++ has never done two-phase name binding; that's an area that needs work for standards conformance. This testcase worked properly by accident in 3.4 and 4.0, because of an optimization which was disallowed under DR 164.
Subject: Bug 38030 Author: jason Date: Fri Nov 14 21:57:34 2008 New Revision: 141866 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141866 Log: PR c++/38030 * semantics.c (finish_call_expr): Remember the result of non-dependent overload resolution. Added: trunk/gcc/testsuite/g++.dg/template/lookup8.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/semantics.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 38030 Author: jason Date: Fri Nov 14 22:01:12 2008 New Revision: 141868 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141868 Log: PR c++/38030 * semantics.c (finish_call_expr): Don't repeat arg-dep lookup for a non-dependent call. Added: branches/gcc-4_3-branch/gcc/testsuite/g++.dg/template/lookup8.C - copied unchanged from r141866, trunk/gcc/testsuite/g++.dg/template/lookup8.C Modified: branches/gcc-4_3-branch/gcc/cp/ChangeLog branches/gcc-4_3-branch/gcc/cp/semantics.c branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
Subject: Bug 38030 Author: jason Date: Fri Nov 14 23:06:11 2008 New Revision: 141872 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141872 Log: PR c++/38030 * semantics.c (finish_call_expr): Don't repeat arg-dep lookup for a non-dependent call. Added: branches/gcc-4_2-branch/gcc/testsuite/g++.dg/template/lookup8.C - copied unchanged from r141866, trunk/gcc/testsuite/g++.dg/template/lookup8.C Modified: branches/gcc-4_2-branch/gcc/cp/ChangeLog branches/gcc-4_2-branch/gcc/cp/semantics.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
Fixed.
Subject: Re: [4.2/4.3/4.4 Regression] name-lookup for non-dependent name in template function is wrong On Fri, 14 Nov 2008, jason at gcc dot gnu dot org wrote: > ------- Comment #5 from jason at gcc dot gnu dot org 2008-11-14 18:29 ------- > G++ has never done two-phase name binding; that's an area that needs work for > standards conformance. Doh. That seems to be a pretty important semantic piece of C++ though ;) Thanks for fixing this bug so quickly. Richard.
*** Bug 39534 has been marked as a duplicate of this bug. ***
Subject: Bug 38030 Author: jason Date: Tue Mar 31 15:42:58 2009 New Revision: 145360 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145360 Log: PR c++/38030, 38850, 39070 * pt.c (type_dependent_expression_p_push): New fn. (tsubst_copy_and_build) [CALL_EXPR]: Only do arg-dep lookup when the substitution makes the call non-dependent. Preserve koenig_p. * parser.c (cp_parser_postfix_expression): Only do arg-dep lookup for non-dependent calls. * semantics.c (finish_call_expr): Revert earlier changes. * cp-tree.h: Revert change to finish_call_expr prototype. Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/cp-tree.h trunk/gcc/cp/parser.c trunk/gcc/cp/pt.c trunk/gcc/cp/semantics.c
Subject: Bug 38030 Author: jason Date: Thu Apr 2 18:37:57 2009 New Revision: 145468 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145468 Log: * mangle.c (write_expression): Mangle dependent name as source-name. PR c++/38030, 38850, 39070 * pt.c (type_dependent_expression_p_push): New fn. (tsubst_copy_and_build) [CALL_EXPR]: Only do arg-dep lookup when the substitution makes the call non-dependent. Preserve koenig_p. * parser.c (cp_parser_postfix_expression): Only do arg-dep lookup for non-dependent calls. * semantics.c (finish_call_expr): Revert earlier changes. * cp-tree.h: Revert change to finish_call_expr prototype. Modified: branches/gcc-4_4-branch/gcc/cp/ChangeLog branches/gcc-4_4-branch/gcc/cp/cp-tree.h branches/gcc-4_4-branch/gcc/cp/mangle.c branches/gcc-4_4-branch/gcc/cp/parser.c branches/gcc-4_4-branch/gcc/cp/pt.c branches/gcc-4_4-branch/gcc/cp/semantics.c branches/gcc-4_4-branch/gcc/testsuite/ChangeLog branches/gcc-4_4-branch/gcc/testsuite/g++.dg/cpp0x/auto12.C branches/gcc-4_4-branch/gcc/testsuite/g++.dg/cpp0x/auto6.C
Subject: Bug 38030 Author: jason Date: Fri Apr 3 18:04:39 2009 New Revision: 145511 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145511 Log: PR c++/38030, 38850, 39070 * pt.c (type_dependent_expression_p_push): New fn. (tsubst_copy_and_build) [CALL_EXPR]: Only do arg-dep lookup when the substitution makes the call non-dependent. Preserve koenig_p. * parser.c (cp_parser_postfix_expression): Only do arg-dep lookup for non-dependent calls. * semantics.c (finish_call_expr): Revert earlier changes. * cp-tree.h: Revert change to finish_call_expr prototype. Modified: branches/gcc-4_3-branch/gcc/cp/ChangeLog branches/gcc-4_3-branch/gcc/cp/cp-tree.h branches/gcc-4_3-branch/gcc/cp/parser.c branches/gcc-4_3-branch/gcc/cp/pt.c branches/gcc-4_3-branch/gcc/cp/semantics.c