OSDN Git Service

cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Sep 2003 17:07:53 +0000 (17:07 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 18 Sep 2003 17:07:53 +0000 (17:07 +0000)
PR c++/9848
* optimize.c (maybe_clone_body): Don't set MARK_USED on parameters
here.
* semantics.c (expand_body): Set it here on the remaining clones.
testsuite:
PR c++/9848
* g++.dg/warn/Wunused-4.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@71528 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/optimize.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wunused-4.C [new file with mode: 0644]

index 1d3c8b2..ad41de2 100644 (file)
@@ -1,3 +1,10 @@
+2003-09-18  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/9848
+       * optimize.c (maybe_clone_body): Don't set MARK_USED on parameters
+       here.
+       * semantics.c (expand_body): Set it here on the remaining clones.
+
 2003-09-18  Roger Sayle  <roger@eyesopen.com>
 
        * lex.c (init_operators): Remove operator_name_info for FFS_EXPR.
index 3204311..2b7df6c 100644 (file)
@@ -120,7 +120,6 @@ bool
 maybe_clone_body (tree fn)
 {
   tree clone;
-  bool first = true;
 
   /* We only clone constructors and destructors.  */
   if (!DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn)
@@ -139,7 +138,7 @@ maybe_clone_body (tree fn)
      list.  */
   for (clone = TREE_CHAIN (fn);
        clone && DECL_CLONED_FUNCTION_P (clone);
-       clone = TREE_CHAIN (clone), first = false)
+       clone = TREE_CHAIN (clone))
     {
       tree parm;
       tree clone_parm;
@@ -175,13 +174,8 @@ maybe_clone_body (tree fn)
        clone_parm = TREE_CHAIN (clone_parm);
       for (; parm;
           parm = TREE_CHAIN (parm), clone_parm = TREE_CHAIN (clone_parm))
-       {
-         /* Update this parameter.  */
-         update_cloned_parm (parm, clone_parm);
-         /* We should only give unused information for one clone.  */
-         if (!first)
-           TREE_USED (clone_parm) = 1;
-       }
+       /* Update this parameter.  */
+       update_cloned_parm (parm, clone_parm);
 
       /* Start processing the function.  */
       push_to_top_level ();
index 37dca0a..ef42579 100644 (file)
@@ -2887,6 +2887,26 @@ expand_body (tree fn)
      static duration objects.  */
   if (DECL_STATIC_DESTRUCTOR (fn))
     static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
+
+  if (DECL_CLONED_FUNCTION_P (fn))
+    {
+      /* If this is a clone, go through the other clones now and mark
+         their parameters used.  We have to do that here, as we don't
+         know whether any particular clone will be expanded, and
+         therefore cannot pick one arbitrarily.  */ 
+      tree probe;
+
+      for (probe = TREE_CHAIN (DECL_CLONED_FUNCTION (fn));
+          probe && DECL_CLONED_FUNCTION_P (probe);
+          probe = TREE_CHAIN (probe))
+       {
+         tree parms;
+
+         for (parms = DECL_ARGUMENTS (probe);
+              parms; parms = TREE_CHAIN (parms))
+           TREE_USED (parms) = 1;
+       }
+    }
 }
 
 /* Generate RTL for FN.  */
index dcef4f4..4315a0f 100644 (file)
@@ -1,3 +1,8 @@
+2003-09-18  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/9848
+       * g++.dg/warn/Wunused-4.C: New test.
+
 2003-09-18  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/12316
diff --git a/gcc/testsuite/g++.dg/warn/Wunused-4.C b/gcc/testsuite/g++.dg/warn/Wunused-4.C
new file mode 100644 (file)
index 0000000..9018e92
--- /dev/null
@@ -0,0 +1,30 @@
+// { dg-do compile }
+// { dg-options "-Wunused-parameter" }
+
+// Copyright (C) 2003 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 15 Sep 2003 <nathan@codesourcery.com>
+// Origin: yotamm@mellanox.co.il
+
+
+// PR c++/9848. Missing warning
+
+struct C1 {
+  // Only use in-charge ctor
+  C1(int bi) {}  // { dg-warning "unused parameter" "" }
+};
+struct C2 {
+  // Only use base ctor
+  C2(int bi) {}  // { dg-warning "unused parameter" "" }
+};
+
+struct D : C2
+{
+  D (int) : C2 (1) {}
+};
+
+void show_compile_warning ()
+{
+  C1 c1 (1);
+  
+  D d (1);
+}