This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/38030
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 14 Nov 2008 16:57:01 -0500
- Subject: C++ PATCH for c++/38030
38038 is a bug report about us not doing two-phase name lookup, which
we've never done. In 3.4 and 4.0 the testcase worked as expected anyway
because we were ignoring the current namespace when doing
argument-dependent lookup, which was wrong; when that was fixed the
testcase broke.
However, when I look at the code it seems that all we need to do to make
this work is stop doing arg-dependent lookup in phase 2 when we have a
non-dependent call. Presto, two-phase name lookup: we are already
storing the correct overload set in the CALL_EXPR in the template. A
further refinement would be to just store the function chosen by the
overload resolution we're already doing at template parsing time, but
that gets complicated and this works fine.
Tested x86_64-pc-linux-gnu, applied to trunk. Will test and apply to
4.3/4.2 as appropriate.
2008-11-14 Jason Merrill <jason@redhat.com>
PR c++/38030
* semantics.c (finish_call_expr): Remember the result of
non-dependent overload resolution.
* g++.dg/template/lookup8.C: New test.
Index: cp/semantics.c
===================================================================
*** cp/semantics.c (revision 141842)
--- cp/semantics.c (working copy)
*************** finish_call_expr (tree fn, tree args, bo
*** 1976,1982 ****
if (processing_template_decl)
{
result = build_call_list (TREE_TYPE (result), orig_fn, orig_args);
! KOENIG_LOOKUP_P (result) = koenig_p;
}
return result;
}
--- 1976,1984 ----
if (processing_template_decl)
{
result = build_call_list (TREE_TYPE (result), orig_fn, orig_args);
! /* Don't repeat arg-dependent lookup at instantiation time if this call
! is not type-dependent. */
! KOENIG_LOOKUP_P (result) = 0;
}
return result;
}
Index: testsuite/g++.dg/template/lookup8.C
===================================================================
*** testsuite/g++.dg/template/lookup8.C (revision 0)
--- testsuite/g++.dg/template/lookup8.C (revision 0)
***************
*** 0 ****
--- 1,19 ----
+ // PR c++/38030
+ // The call to f should be resolved at template definition time.
+ // { dg-do link }
+
+ struct B { };
+ struct D : public B { };
+ D d;
+ void f (B &) { }
+ template < class T >
+ void g ()
+ {
+ return f (d);
+ }
+ void f (D &);
+ int main ()
+ {
+ g<int> ();
+ return 0;
+ }