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]: Fix bug 2356


Hi,
I've installed this obvious fix for 2356 on both mainline and branch.

A function's definition can name parameters differently to the declaration.
That information should be propagated to the clones, otherwise unused
parameter warnings are wrong &/| confusing.

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

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-04-27  Nathan Sidwell  <nathan@codesourcery.com>

	* optimize.c (maybe_clone_body): Copy parameter names and locations.

Index: cp/optimize.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/optimize.c,v
retrieving revision 1.51.2.14
diff -c -3 -p -r1.51.2.14 optimize.c
*** optimize.c	2001/04/26 00:29:51	1.51.2.14
--- optimize.c	2001/04/27 12:14:30
*************** maybe_clone_body (fn)
*** 1019,1024 ****
--- 1019,1025 ----
  {
    inline_data id;
    tree clone;
+   int first = 1;
  
    /* We only clone constructors and destructors.  */
    if (!DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
*************** maybe_clone_body (fn)
*** 1032,1038 ****
       list.  */
    for (clone = TREE_CHAIN (fn);
         clone && DECL_CLONED_FUNCTION_P (clone);
!        clone = TREE_CHAIN (clone))
      {
        tree parm;
        tree clone_parm;
--- 1033,1039 ----
       list.  */
    for (clone = TREE_CHAIN (fn);
         clone && DECL_CLONED_FUNCTION_P (clone);
!        clone = TREE_CHAIN (clone), first = 0)
      {
        tree parm;
        tree clone_parm;
*************** maybe_clone_body (fn)
*** 1053,1058 ****
--- 1054,1083 ----
        DECL_NOT_REALLY_EXTERN (clone) = DECL_NOT_REALLY_EXTERN (fn);
        TREE_PUBLIC (clone) = TREE_PUBLIC (fn);
  
+       /* Adjust the parameter names and locations. */
+       parm = DECL_ARGUMENTS (fn);
+       clone_parm = DECL_ARGUMENTS (clone);
+       if (DECL_HAS_IN_CHARGE_PARM_P (fn))
+ 	parm = TREE_CHAIN (parm);
+       if (DECL_HAS_VTT_PARM_P (fn))
+ 	parm = TREE_CHAIN (parm);
+       if (DECL_HAS_VTT_PARM_P (clone))
+ 	clone_parm = TREE_CHAIN (clone_parm);
+       for (; parm;
+ 	   parm = TREE_CHAIN (parm), clone_parm = TREE_CHAIN (clone_parm))
+ 	{
+ 	  DECL_ABSTRACT_ORIGIN (clone_parm) = parm;
+ 
+ 	  /* The name may have changed from the declaration. */
+ 	  DECL_NAME (clone_parm) = DECL_NAME (parm);
+ 	  DECL_SOURCE_FILE (clone_parm) = DECL_SOURCE_FILE (parm);
+ 	  DECL_SOURCE_LINE (clone_parm) = DECL_SOURCE_LINE (parm);
+  
+ 	  /* We should only give unused information for one clone. */
+ 	  if (!first)
+ 	    TREE_USED (clone_parm) = 1;
+ 	}
+ 
        /* Start processing the function.  */
        push_to_top_level ();
        start_function (NULL_TREE, clone, NULL_TREE, SF_PRE_PARSED);
*************** maybe_clone_body (fn)
*** 1115,1121 ****
  	     function.  */
  	  else
  	    {
- 	      DECL_ABSTRACT_ORIGIN (clone_parm) = parm;
  	      splay_tree_insert (id.decl_map,
  				 (splay_tree_key) parm,
  				 (splay_tree_value) clone_parm);
--- 1140,1145 ----
// Build don't link:
// Special g++ Options: -W -Wall
// 
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 April 2001 <nathan@codesourcery.com>

// Bug 2356. Unused parameter information introduced in a ctor
// definition was not propagated to clones, leading to missed or
// unwarranted unused parameter warnings, possibly given twice.

struct X
{
  X(int i);
  void foo (int i);
  
};
void foo (int i);

X::X(int)
{
}
void X::foo (int) 
{
}
void foo (int)
{
}

struct Y
{
  Y(int);
  void bar (int);
  
};
void bar (int);

Y::Y(int i)
{ // WARNING - unused parameter
}
void Y::bar (int i) 
{ // WARNING - unused parameter
}
void bar (int i)
{ // WARNING - unused parameter
}

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