PATCH for member template function crash

Mark Mitchell mark@markmitchell.com
Tue Aug 4 11:42:00 GMT 1998


Here's a patch for:

  template<class T>
  class foo {
    T deft;

    template<class U> int priv (U u, T t) { return u - t; }
  public:
    foo (T t) : deft (t) {}

    template<class U> int pub (U u) {
      int (foo::*fn) (U, T);
      fn = &foo<T>::template priv<U>;
      return (this->*fn) (u, deft);
    }
  };

  int
  main ()
  {
    foo<long> fff (5);
    return fff.pub (3);
  }

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1998-08-04  Mark Mitchell  <mark@markmitchell.com>

	* init.c (build_offset_ref): Deal with a TEMPLATE_ID_EXPR whose
	name is a LOOKUP_EXPR, rather than an IDENTIFIER_NODE.

Index: testsuite/g++.old-deja/g++.pt/crash18.C
===================================================================
RCS file: crash18.C
diff -N crash18.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- crash18.C	Tue Aug  4 11:23:06 1998
***************
*** 0 ****
--- 1,23 ----
+ // Build don't run:
+ 
+ template<class T>
+ class foo {
+   T deft;
+ 
+   template<class U> int priv (U u, T t) { return u - t; }
+ public:
+   foo (T t) : deft (t) {}
+ 
+   template<class U> int pub (U u) {
+     int (foo::*fn) (U, T);
+     fn = &foo<T>::template priv<U>;
+     return (this->*fn) (u, deft);
+   }
+ };
+ 
+ int
+ main ()
+ {
+   foo<long> fff (5);
+   return fff.pub (3);
+ }
Index: cp/init.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/init.c,v
retrieving revision 1.55
diff -c -p -r1.55 init.c
*** init.c	1998/08/01 02:36:54	1.55
--- init.c	1998/08/04 18:24:10
*************** build_offset_ref (type, name)
*** 1547,1552 ****
--- 1547,1557 ----
  	 part, we treat this just like a.f.  We do remember, however,
  	 the template-id that was used.  */
        name = TREE_OPERAND (orig_name, 0);
+ 
+       if (TREE_CODE (name) == LOOKUP_EXPR)
+ 	/* This can happen during tsubst'ing.  */
+ 	name = TREE_OPERAND (name, 0);
+ 
        my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 0);
      }
  



More information about the Gcc-patches mailing list