This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 6412
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 20 Mar 2003 23:11:47 -0800
- Subject: C++ PATCH: PR 6412
- Reply-to: mark at codesourcery dot com
This patch fixes a crash involving templates and friends. (Boy, is
that a fragile area of the compiler and a complex area of the
standard...)
Tested on i686-pc-linux-gnu, applied on the mainline and on the
branch.
--
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery dot com
2003-03-20 Mark Mitchell <mark at codesourcery dot com>
PR c++/6412
* cp/decl2.c (arg_assoc_class): Correct check for namespace-scope
friends.
* cp/pt.c (instantiate_class_template): Fix formatting.
2003-03-20 Mark Mitchell <mark at codesourcery dot com>
PR c++/6412
* g++.dg/template/friend17.C: New test.
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.609
diff -c -5 -p -r1.609 decl2.c
*** cp/decl2.c 20 Mar 2003 21:14:30 -0000 1.609
--- cp/decl2.c 21 Mar 2003 07:02:05 -0000
*************** arg_assoc_class (struct arg_lookup *k, t
*** 3961,3971 ****
if (k->name == FRIEND_NAME (list))
for (friends = FRIEND_DECLS (list); friends;
friends = TREE_CHAIN (friends))
/* Only interested in global functions with potentially hidden
(i.e. unqualified) declarations. */
! if (decl_namespace (TREE_VALUE (friends)) == context)
if (add_function (k, TREE_VALUE (friends)))
return true;
/* Process template arguments. */
if (CLASSTYPE_TEMPLATE_INFO (type))
--- 3961,3971 ----
if (k->name == FRIEND_NAME (list))
for (friends = FRIEND_DECLS (list); friends;
friends = TREE_CHAIN (friends))
/* Only interested in global functions with potentially hidden
(i.e. unqualified) declarations. */
! if (CP_DECL_CONTEXT (TREE_VALUE (friends)) == context)
if (add_function (k, TREE_VALUE (friends)))
return true;
/* Process template arguments. */
if (CLASSTYPE_TEMPLATE_INFO (type))
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.671
diff -c -5 -p -r1.671 pt.c
*** cp/pt.c 16 Mar 2003 14:36:43 -0000 1.671
--- cp/pt.c 21 Mar 2003 07:02:08 -0000
*************** instantiate_class_template (type)
*** 5546,5561 ****
if (TREE_CODE (friend_type) == TEMPLATE_DECL)
--processing_template_decl;
}
else
! {
! /* Build new DECL_FRIENDLIST. */
!
! add_friend (type,
! tsubst_friend_function (t, args));
! }
}
}
/* Set the file and line number information to whatever is given for
the class itself. This puts error messages involving generated
--- 5546,5557 ----
if (TREE_CODE (friend_type) == TEMPLATE_DECL)
--processing_template_decl;
}
else
! /* Build new DECL_FRIENDLIST. */
! add_friend (type, tsubst_friend_function (t, args));
}
}
/* Set the file and line number information to whatever is given for
the class itself. This puts error messages involving generated
Index: testsuite/g++.dg/template/friend17.C
===================================================================
RCS file: testsuite/g++.dg/template/friend17.C
diff -N testsuite/g++.dg/template/friend17.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/friend17.C 21 Mar 2003 07:02:08 -0000
***************
*** 0 ****
--- 1,12 ----
+ template <class T>
+ struct X {
+ template <class U> void operator+=(U);
+
+ template <class V>
+ template <class U>
+ friend void X<V>::operator+=(U);
+ };
+
+ int main() {
+ X<int>() += 1.0;
+ }