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]: Fix 9483


Hi,
I've installed this obvious patch to fix 9483. (Anther place where
static tree type checking would have caught this earlier.)

booted & tested on i686-pc-linux-gnu.

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
         The voices in my head said this was stupid too
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2003-07-09  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++ 9483
	* class.c (check_field_decls): Pass DECL_NAME to constructor_name_p.
	* decl2.c (constructor_name_p): Avoid repeated constructor_name
	calls.
	* decl.c (grokdeclarator): Refactor ctor/dtor detection.

Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.550
diff -c -3 -p -r1.550 class.c
*** cp/class.c	8 Jul 2003 01:38:41 -0000	1.550
--- cp/class.c	10 Jul 2003 08:47:07 -0000
*************** check_field_decls (tree t, tree *access_
*** 3177,3183 ****
        /* Core issue 80: A nonstatic data member is required to have a
  	 different name from the class iff the class has a
  	 user-defined constructor.  */
!       if (constructor_name_p (x, t) && TYPE_HAS_CONSTRUCTOR (t))
  	cp_pedwarn_at ("field `%#D' with same name as class", x);
  
        /* We set DECL_C_BIT_FIELD in grokbitfield.
--- 3177,3183 ----
        /* Core issue 80: A nonstatic data member is required to have a
  	 different name from the class iff the class has a
  	 user-defined constructor.  */
!       if (constructor_name_p (DECL_NAME (x), t) && TYPE_HAS_CONSTRUCTOR (t))
  	cp_pedwarn_at ("field `%#D' with same name as class", x);
  
        /* We set DECL_C_BIT_FIELD in grokbitfield.
Index: cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1084
diff -c -3 -p -r1.1084 decl.c
*** cp/decl.c	9 Jul 2003 00:31:15 -0000	1.1084
--- cp/decl.c	10 Jul 2003 08:47:37 -0000
*************** grokdeclarator (tree declarator,
*** 9911,9926 ****
  	      decl = *next;
  	      if (ctype)
  		{
! 		  if (TREE_CODE (decl) == IDENTIFIER_NODE
! 		      && constructor_name_p (decl, ctype))
  		    {
  		      sfk = sfk_constructor;
  		      ctor_return_type = ctype;
  		    }
! 		  else if (TREE_CODE (decl) == BIT_NOT_EXPR
! 			   && TREE_CODE (TREE_OPERAND (decl, 0)) == IDENTIFIER_NODE
! 			   && constructor_name_p (TREE_OPERAND (decl, 0),
! 						  ctype))
  		    {
  		      sfk = sfk_destructor;
  		      ctor_return_type = ctype;
--- 9911,9929 ----
  	      decl = *next;
  	      if (ctype)
  		{
! 		  tree name = decl;
! 
! 		  if (TREE_CODE (name) == BIT_NOT_EXPR)
! 		    name = TREE_OPERAND (name, 0);
! 
! 		  if (!constructor_name_p (decl, ctype))
! 		    ;
! 		  else if (decl == name)
  		    {
  		      sfk = sfk_constructor;
  		      ctor_return_type = ctype;
  		    }
! 		  else
  		    {
  		      sfk = sfk_destructor;
  		      ctor_return_type = ctype;
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.646
diff -c -3 -p -r1.646 decl2.c
*** cp/decl2.c	9 Jul 2003 08:47:59 -0000	1.646
--- cp/decl2.c	10 Jul 2003 08:47:45 -0000
*************** constructor_name (tree type)
*** 1190,1197 ****
  bool
  constructor_name_p (tree name, tree type)
  {
!   return (name == constructor_name (type)
! 	  || name == constructor_name_full (type));
  }
  
  
--- 1190,1210 ----
  bool
  constructor_name_p (tree name, tree type)
  {
!   tree ctor_name;
! 
!   if (!name)
!     return false;
!   
!   if (TREE_CODE (name) != IDENTIFIER_NODE)
!     return false;
!   
!   ctor_name = constructor_name_full (type);
!   if (name == ctor_name)
!     return true;
!   if (IDENTIFIER_TEMPLATE (ctor_name)
!       && name == IDENTIFIER_TEMPLATE (ctor_name))
!     return true;
!   return false;
  }
  
  
// { dg-do compile }

// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 9 Jul 2003 <nathan@codesourcery.com>

// PR c++ 9483.  accepted fields with same name as class

struct test
{
  char test;  // { dg-error "with same name as class" "" }
  test();
};

template <typename T> struct X
{
  char X;  // { dg-error "with same name as class" "" }
  X ();
};

template <> struct X<int> {
  char X;  // { dg-error "with same name as class" "" }
  X();
};

X<float> i; // { dg-error "instantiated from" "" }

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