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]
Other format: [Raw text]

[C++ PATCH] cleanups


This patch cleans up a couple of places I notce in fixing the previous two bugs.

In start_decl we were setting the explicit instantiation flag and then immediately checking whether we'd set it. The check to see if the context is an instantiation appears unneeded.

In discriminator_for_local_decl we were getting a seg fault, rather than bounds error, because we were not using VEC_index.

built & tested on i686-pc-linux-gnu, installed mainline

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2005-06-02  Nathan Sidwell  <nathan@codesourcery.com>

	* decl.c (start_decl): Simplify specialization handling. Remove
	unneeded CLASSTYPE_TEMPLATE_INSTANTIATION check.
	* mangle.c (discriminator_for_local_entity): Use VEC_index.

Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1399
diff -c -3 -p -r1.1399 decl.c
*** cp/decl.c	27 May 2005 23:17:08 -0000	1.1399
--- cp/decl.c	2 Jun 2005 09:03:24 -0000
*************** start_decl (const cp_declarator *declara
*** 3715,3736 ****
  
        /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
        DECL_IN_AGGR_P (decl) = 0;
!       if ((DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
! 	  || CLASSTYPE_TEMPLATE_INSTANTIATION (context))
  	{
! 	  /* Do not mark DECL as an explicit specialization if it was
! 	     not already marked as an instantiation; a declaration
! 	     should never be marked as a specialization unless we know
! 	     what template is being specialized.  */ 
! 	  if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
! 	    SET_DECL_TEMPLATE_SPECIALIZATION (decl);
  	  /* [temp.expl.spec] An explicit specialization of a static data
  	     member of a template is a definition if the declaration
  	     includes an initializer; otherwise, it is a declaration.
! 
  	     We check for processing_specialization so this only applies
  	     to the new specialization syntax.  */
! 	  if (DECL_INITIAL (decl) == NULL_TREE && processing_specialization)
  	    DECL_EXTERNAL (decl) = 1;
  	}
  
--- 3716,3737 ----
  
        /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set.  */
        DECL_IN_AGGR_P (decl) = 0;
!       /* Do not mark DECL as an explicit specialization if it was not
! 	 already marked as an instantiation; a declaration should
! 	 never be marked as a specialization unless we know what
! 	 template is being specialized.  */ 
!       if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
  	{
! 	  SET_DECL_TEMPLATE_SPECIALIZATION (decl);
!       
  	  /* [temp.expl.spec] An explicit specialization of a static data
  	     member of a template is a definition if the declaration
  	     includes an initializer; otherwise, it is a declaration.
! 	      
  	     We check for processing_specialization so this only applies
  	     to the new specialization syntax.  */
! 	  if (!DECL_INITIAL (decl)
! 	      && processing_specialization)
  	    DECL_EXTERNAL (decl) = 1;
  	}
  
Index: cp/mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.123
diff -c -3 -p -r1.123 mangle.c
*** cp/mangle.c	7 May 2005 09:48:21 -0000	1.123
--- cp/mangle.c	2 Jun 2005 09:03:32 -0000
*************** write_special_name_destructor (const tre
*** 1426,1433 ****
  static int
  discriminator_for_local_entity (tree entity)
  {
-   tree *type;
- 
    /* Assume this is the only local entity with this name.  */
    int discriminator = 0;
  
--- 1426,1431 ----
*************** discriminator_for_local_entity (tree ent
*** 1435,1446 ****
      discriminator = DECL_DISCRIMINATOR (entity);
    else if (TREE_CODE (entity) == TYPE_DECL)
      {
        /* Scan the list of local classes.  */
        entity = TREE_TYPE (entity);
!       for (type = VEC_address (tree, local_classes); *type != entity; ++type)
!         if (TYPE_IDENTIFIER (*type) == TYPE_IDENTIFIER (entity)
!             && TYPE_CONTEXT (*type) == TYPE_CONTEXT (entity))
! 	  ++discriminator;
      }  
  
    return discriminator;
--- 1433,1451 ----
      discriminator = DECL_DISCRIMINATOR (entity);
    else if (TREE_CODE (entity) == TYPE_DECL)
      {
+       int ix;
+       
        /* Scan the list of local classes.  */
        entity = TREE_TYPE (entity);
!       for (ix = 0; ; ix++)
! 	{
! 	  tree type = VEC_index (tree, local_classes, ix);
! 	  if (type == entity)
! 	    break;
! 	  if (TYPE_IDENTIFIER (type) == TYPE_IDENTIFIER (entity)
! 	      && TYPE_CONTEXT (type) == TYPE_CONTEXT (entity))
! 	    ++discriminator;
! 	}
      }  
  
    return discriminator;

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