From 0d02a0d5a6bdd987475fe81559b24d0d8e015a7c Mon Sep 17 00:00:00 2001
From: nathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Wed, 11 Apr 2001 08:43:16 +0000
Subject: [PATCH] cp: 	* method.c (implicitly_declare_fn): Commonize code for
 copy ctor 	and assignment op. Set TREE_USED for parameter. testsuite: 
 * g++.old-deja/g++.other/warn6.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@41243 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/cp/ChangeLog                             |  5 ++
 gcc/cp/method.c                              | 52 +++++++++-----------
 gcc/testsuite/ChangeLog                      |  4 ++
 gcc/testsuite/g++.old-deja/g++.other/warn6.C | 17 +++++++
 4 files changed, 50 insertions(+), 28 deletions(-)
 create mode 100644 gcc/testsuite/g++.old-deja/g++.other/warn6.C

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7b5aee39e420..6a871d4d8280 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2001-04-11  Nathan Sidwell  <nathan@codesourcery.com>
+
+	* method.c (implicitly_declare_fn): Commonize code for copy ctor
+	and assignment op. Set TREE_USED for parameter.
+
 2001-04-10  Mark Mitchell  <mark@codesourcery.com>
 
 	* class.c (find_final_overrider_data): Add `candidates'.
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 7c55fd8f9571..2f894846a80a 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -957,8 +957,8 @@ implicitly_declare_fn (kind, type, const_p)
   tree declspecs = NULL_TREE;
   tree fn, args = NULL_TREE;
   tree raises = empty_except_spec;
-  tree argtype;
   int retref = 0;
+  int has_parm = 0;
   tree name = constructor_name (TYPE_IDENTIFIER (type));
 
   switch (kind)
@@ -977,40 +977,33 @@ implicitly_declare_fn (kind, type, const_p)
       break;
 
     case sfk_copy_constructor:
-    {
-      struct copy_data data;
-      
-      if (const_p)
-	type = build_qualified_type (type, TYPE_QUAL_CONST);
-      argtype = build_reference_type (type);
-      args = tree_cons (NULL_TREE,
-			build_tree_list (hash_tree_chain (argtype, NULL_TREE),
-					 get_identifier ("_ctor_arg")),
-			void_list_node);
-      data.name = NULL;
-      data.quals = const_p ? TYPE_QUAL_CONST : 0;
-      raises = synthesize_exception_spec (type, &locate_copy, &data);
-      break;
-    }
     case sfk_assignment_operator:
     {
       struct copy_data data;
+      tree argtype;
       
-      retref = 1;
-      declspecs = build_tree_list (NULL_TREE, type);
+      has_parm = 1;
+      data.name = NULL;
+      data.quals = 0;
+      if (kind == sfk_assignment_operator)
+        {
+          retref = 1;
+          declspecs = build_tree_list (NULL_TREE, type);
 
+          name = ansi_assopname (NOP_EXPR);
+          data.name = name;
+        }
       if (const_p)
-	type = build_qualified_type (type, TYPE_QUAL_CONST);
-
-      name = ansi_assopname (NOP_EXPR);
-
+        {
+          data.quals = TYPE_QUAL_CONST;
+          type = build_qualified_type (type, TYPE_QUAL_CONST);
+        }
+    
       argtype = build_reference_type (type);
-      args = tree_cons (NULL_TREE,
-			build_tree_list (hash_tree_chain (argtype, NULL_TREE),
-					 get_identifier ("_ctor_arg")),
-			void_list_node);
-      data.name = name;
-      data.quals = const_p ? TYPE_QUAL_CONST : 0;
+      args = build_tree_list (hash_tree_chain (argtype, NULL_TREE),
+			      get_identifier ("_ctor_arg"));
+      args = tree_cons (NULL_TREE, args, void_list_node);
+      
       raises = synthesize_exception_spec (type, &locate_copy, &data);
       break;
     }
@@ -1022,10 +1015,13 @@ implicitly_declare_fn (kind, type, const_p)
 
   {
     tree declarator = make_call_declarator (name, args, NULL_TREE, raises);
+    
     if (retref)
       declarator = build_nt (ADDR_EXPR, declarator);
 
     fn = grokfield (declarator, declspecs, NULL_TREE, NULL_TREE, NULL_TREE);
+    if (has_parm)
+      TREE_USED (FUNCTION_FIRST_USER_PARM (fn)) = 1;
   }
 
   my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 20000408);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ef3667496dd4..df0f05ba7f39 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2001-04-11  Nathan Sidwell  <nathan@codesourcery.com>
+
+	* g++.old-deja/g++.other/warn6.C: New test.
+
 22001-04-11  Peter Schmid  <schmid@snake.iap.physik.tu-darmstadt.de>
 
         * g++.old-deja/g++.robertl/eb42.C: Same.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/warn6.C b/gcc/testsuite/g++.old-deja/g++.other/warn6.C
new file mode 100644
index 000000000000..1a54b3297894
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/warn6.C
@@ -0,0 +1,17 @@
+// Build don't link:
+// Special g++ Options: -W -Wall
+
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 2 Mar 2001 <nathan@codesourcery.com>
+
+// Bug 2139. We gave an erronous warning about an unused parm on a
+// synthesized function
+
+struct A
+{
+  virtual ~A ();
+};
+void foo (A const &a)
+{
+  A a1 = a;
+}
-- 
GitLab