This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for member template classes
- To: egcs-patches at cygnus dot com
- Subject: C++ PATCH for member template classes
- From: Mark Mitchell <mark at markmitchell dot com>
- Date: Sun, 11 Oct 1998 17:41:25 -0700
- Cc: Jason Merrill <jason at cygnus dot com>
- Reply-to: mark at markmitchell dot com
This small patch fixes a bug in the unification of member class
templates that arises with use of the std::auto_ptr<T>::auto_ptr_ref
template.
--
Mark Mitchell mark@markmitchell.com
Mark Mitchell Consulting http://www.markmitchell.com
1998-10-11 Mark Mitchell <mark@markmitchell.com>
* cp-tree.h (specializations_of_same_template_p): Declare.
* pt.c (specializations_of_same_template_p): New function.
(unify): Use it.
* search.c (get_template_base): Use it.
(get_template_base_recursive): Likewise.
Index: testsuite/g++.old-deja/g++.pt/memclass17.C
===================================================================
RCS file: memclass17.C
diff -N memclass17.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- memclass17.C Sun Oct 11 17:33:45 1998
***************
*** 0 ****
--- 1,22 ----
+ // Build don't link:
+
+ template <class T> struct S
+ {
+ template <class U> struct I
+ {
+ };
+
+ S();
+ S(S& s);
+ S(I<T>);
+
+ template <class U> operator I<U>();
+ };
+
+ S<int> f();
+ void g(S<int>);
+
+ void h()
+ {
+ g(f());
+ }
Index: cp/cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.149
diff -c -p -r1.149 cp-tree.h
*** cp-tree.h 1998/10/09 00:10:55 1.149
--- cp-tree.h 1998/10/12 00:33:58
*************** extern int is_specialization_of
*** 2869,2874 ****
--- 2869,2875 ----
extern int comp_template_args PROTO((tree, tree));
extern void maybe_process_partial_specialization PROTO((tree));
extern void maybe_check_template_type PROTO((tree));
+ extern int specializations_of_same_template_p PROTO((tree, tree));
extern int processing_specialization;
extern int processing_explicit_instantiation;
Index: cp/search.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/search.c,v
retrieving revision 1.57
diff -c -p -r1.57 search.c
*** search.c 1998/10/09 11:01:40 1.57
--- search.c 1998/10/12 00:34:07
*************** get_template_base_recursive (binfo, rval
*** 3317,3323 ****
tree type = BINFO_TYPE (binfo);
if (CLASSTYPE_TEMPLATE_INFO (type)
! && CLASSTYPE_TI_TEMPLATE (type) == template)
{
if (rval == NULL_TREE || rval == type)
return type;
--- 3317,3324 ----
tree type = BINFO_TYPE (binfo);
if (CLASSTYPE_TEMPLATE_INFO (type)
! && specializations_of_same_template_p (TREE_TYPE (template),
! type))
{
if (rval == NULL_TREE || rval == type)
return type;
*************** get_template_base (template, binfo)
*** 3375,3381 ****
my_friendly_abort (92);
if (CLASSTYPE_TEMPLATE_INFO (type)
! && CLASSTYPE_TI_TEMPLATE (type) == template)
return type;
rval = get_template_base_recursive (binfo, NULL_TREE, template, 0);
--- 3376,3383 ----
my_friendly_abort (92);
if (CLASSTYPE_TEMPLATE_INFO (type)
! && specializations_of_same_template_p (TREE_TYPE (template),
! type))
return type;
rval = get_template_base_recursive (binfo, NULL_TREE, template, 0);
Index: cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.211
diff -c -p -r1.211 pt.c
*** pt.c 1998/10/09 00:10:57 1.211
--- pt.c 1998/10/12 00:34:30
*************** is_specialization_of (decl, tmpl)
*** 756,761 ****
--- 756,777 ----
return 0;
}
+ /* Returns nonzero if T1 and T2 are instances of the same template.
+ (They may have different template arguments.) */
+
+ int
+ specializations_of_same_template_p (t1, t2)
+ tree t1;
+ tree t2;
+ {
+ /* For now, we only deal with instances of class templates, since
+ that is the only way in which this function is used. */
+
+ return (most_general_template (CLASSTYPE_TI_TEMPLATE (t1))
+ == most_general_template (CLASSTYPE_TI_TEMPLATE (t2)));
+ }
+
+
/* Register the specialization SPEC as a specialization of TMPL with
the indicated ARGS. Returns SPEC, or an equivalent prior
declaration, if available. */
*************** unify (tparms, targs, parm, arg, strict,
*** 7340,7351 ****
can be a derived class of the deduced A. Likewise, if
P is a pointer to a class of the form template-id, A
can be a pointer to a derived class pointed to by the
! deduced A. */
t = get_template_base (CLASSTYPE_TI_TEMPLATE (parm), arg);
! else if
! (CLASSTYPE_TEMPLATE_INFO (arg)
! && CLASSTYPE_TI_TEMPLATE (parm) == CLASSTYPE_TI_TEMPLATE (arg))
t = arg;
if (! t || t == error_mark_node)
return 1;
--- 7356,7373 ----
can be a derived class of the deduced A. Likewise, if
P is a pointer to a class of the form template-id, A
can be a pointer to a derived class pointed to by the
! deduced A.
!
! The call to get_template_base also handles the case
! where PARM and ARG are the same type, i.e., where no
! derivation is involved. */
t = get_template_base (CLASSTYPE_TI_TEMPLATE (parm), arg);
! else if (CLASSTYPE_TEMPLATE_INFO (arg)
! && specializations_of_same_template_p (parm, arg))
! /* Perhaps PARM is something like S<U> and ARG is S<int>.
! Then, we should unify `int' and `U'. */
t = arg;
+
if (! t || t == error_mark_node)
return 1;