This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/34870 (argument-dependent lookup and class templates)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 05 Nov 2009 22:38:42 -0500
- Subject: C++ PATCH for c++/34870 (argument-dependent lookup and class templates)
We need to call complete_type on associated classes before we try to
look through their friend lists. Doing that required a change to
instantiate_class_template to use uses_template_parms (which works when
processing_template_decl is false) rather than dependent_type_p (which
doesn't) in order to avoid trying to instantiate the template pattern
itself.
Tested x86_64-pc-linux-gnu, applied to trunk.
commit d880f736136f66fb2e0eea5ec784e07d70f66296
Author: Jason Merrill <jason@redhat.com>
Date: Thu Nov 5 17:14:57 2009 -0500
PR c++/34870
* name-lookup.c (arg_assoc_class): Call complete_type.
* pt.c (instantiate_class_template): Call uses_template_parms
instead of dependent_type_p.
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index c3f742e..14f9787 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -4780,6 +4780,8 @@ arg_assoc_class (struct arg_lookup *k, tree type)
if (arg_assoc_namespace (k, context))
return true;
+ complete_type (type);
+
if (TYPE_BINFO (type))
{
/* Process baseclasses. */
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 74273eb..d4556cd 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -7358,7 +7358,7 @@ instantiate_class_template (tree type)
if (TYPE_BEING_DEFINED (type)
|| COMPLETE_TYPE_P (type)
- || dependent_type_p (type))
+ || uses_template_parms (type))
return type;
/* Figure out which template is being instantiated. */
diff --git a/gcc/testsuite/g++.dg/lookup/koenig7.C b/gcc/testsuite/g++.dg/lookup/koenig7.C
new file mode 100644
index 0000000..bc54ba9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lookup/koenig7.C
@@ -0,0 +1,12 @@
+// PR c++/34870
+
+template <typename T>
+struct Foo
+{
+ friend void func(const Foo &) {}
+};
+
+void check(const Foo<int> & x)
+{
+ func(x);
+}