This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C++ patch for typedef destructors



I don't know if it meets the slush criteria, but...

This patch and testcase are an attempt to add support for constructs like
"p.T::U::~U()", where T::U is a typedef.  At the moment, g++ tries to
look up ~U in the type that T::U is equivalent to, so the name U is lost.

I've checked it with make check-g++ on i686-unknown-gnu-linux and found no
regressions, but I'm not 100% certain how safe it is.  Comments
appreciated.  No commit access, so please check in if OK.

Richard

--------------

// Destructors for nested typedefs can be called explicitly.
// See 5.4.2

struct T { typedef int U; };
T::U p;
void f()
{
  int U;
  p.T::U::~U();
}

---------------

2001-01-22  Richard Sandiford  <r.sandiford@redhat.com>

	* cp/decl.c (lookup_name_real): When called from the lexer, check
	whether the scope type was obtained through a typedef.  If so,
	make sure that the same type is available through the same name
	again (in constructs like U::U() and U::~U()).


Index: ./gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.739
diff -c -d -p -r1.739 decl.c
*** ./gcc/cp/decl.c	2001/01/19 09:24:12	1.739
--- ./gcc/cp/decl.c	2001/01/19 17:33:11
*************** lookup_name_real (name, prefer_type, non
*** 5884,5890 ****

  	  if (TREE_CODE (type) == VOID_TYPE)
  	    type = global_namespace;
! 	  if (TREE_CODE (type) == NAMESPACE_DECL)
  	    {
  	      val = make_node (CPLUS_BINDING);
  	      flags |= LOOKUP_COMPLAIN;
--- 5884,5903 ----

  	  if (TREE_CODE (type) == VOID_TYPE)
  	    type = global_namespace;
!
! 	  /* TYPE may have been obtained through a typedef:
!
! 	           typedef TYPE U
!
! 	     TYPE might not be an aggregate, or might be an aggregate with a
! 	     name other than U.  We must still return the declaration of U
! 	     if NAME == U.  */
! 	  if (lastiddecl
! 	      && TREE_CODE (lastiddecl) == TYPE_DECL
! 	      && TREE_TYPE (lastiddecl) == type
! 	      && name == DECL_NAME (lastiddecl))
! 	    val = lastiddecl;
! 	  else if (TREE_CODE (type) == NAMESPACE_DECL)
  	    {
  	      val = make_node (CPLUS_BINDING);
  	      flags |= LOOKUP_COMPLAIN;



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]