C++ PATCH for taking a pointer to a template member method.

Theodore Papadopoulo Theodore.Papadopoulo@sophia.inria.fr
Mon Mar 20 08:39:00 GMT 2000


The current gcc (from CVS) crashes on inputs like the one in memtemp94.C below.

mururoa->/net/home/robotvis/gnu/egcs.old/bin/g++ memtemp94.C
memtemp94.C: In method `void (H::*H::f ()) () const const':
memtemp94.C:8: Internal compiler error.
memtemp94.C:8: Please submit a full bug report.
memtemp94.C:8: See <URL: http://www.gnu.org/software/gcc/faq.html#bugreport > for instructions.

mururoa->/net/home/robotvis/gnu/egcs.old/bin/g++ -v
Reading specs from /net/home/robotvis/gnu/egcs.old/bin/../lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
gcc version 2.96 20000214 (experimental)

But this is still true with more recent compilers.

The problem seems to be that the code in init.c:build_offset_ref is not prepared
to receive a TEMPLATE_ID_EXPR tree node that contains a COMPONENT_REF one.
The patch below is a fix (not only the compiler crash, but it also calls the proper
function in a more complicated example).

Of course, my understanding of gcc trees being so poor, I adapted the code from
build_new_method_call so that the patch below might be an overkill and/or wrongly
mixed with the LOOKUP_EXPR code.

The compiler has been bootstrapped and no new regression has appeared in the g++
testsuite with the patch.

    Theo.

gcc/testsuite/ChangeLog:

2000-03-20 Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>

    * /g++.old-deja/g++.pt/memtemp94.C: New test.

gcc/ChangeLog:

2000-03-20 Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>

    * init.c (build_offset_ref): Handle the case of a templated member function.
    
New file: gcc/testsuite/g++.old-deja/g++.pt/memtemp94.C
// Build don't link:
// Origin: Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>

struct H {
  template <class T> void k() const { }
  typedef void (H::*pmf)() const;

  pmf f() const { return &H::k<int>; }
};

Index: gcc/cp/init.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/init.c,v
retrieving revision 1.176
diff -c -3 -p -r1.176 init.c
*** init.c	2000/03/19 05:22:04	1.176
--- init.c	2000/03/20 14:52:36
*************** build_offset_ref (type, name)
*** 1577,1585 ****
  	 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);
      }
--- 1577,1597 ----
  	 the template-id that was used.  */
        name = TREE_OPERAND (orig_name, 0);
  
!       if (DECL_P (name))
! 	name = DECL_NAME (name);
!       else
! 	{
! 	  if (TREE_CODE (name) == LOOKUP_EXPR)
! 	    /* This can happen during tsubst'ing.  */
! 	    name = TREE_OPERAND (name, 0);
! 	  else
! 	    {
! 	      if (TREE_CODE (name) == COMPONENT_REF)
! 		name = TREE_OPERAND (name, 1);
! 	      if (TREE_CODE (name) == OVERLOAD)
! 		name = DECL_NAME (OVL_CURRENT (name));
! 	    }
! 	}
  
        my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 0);
      }

 --------------------------------------------------------------------
 Theodore Papadopoulo
 Email: Theodore.Papadopoulo@sophia.inria.fr Tel: (33) 04 92 38 76 01
 --------------------------------------------------------------------





More information about the Gcc-patches mailing list