diff mbox series

[C++] build_clone cleanup

Message ID 13b39e29-91e6-c679-8580-9a3c6c05f64f@acm.org
State New
Headers show
Series [C++] build_clone cleanup | expand

Commit Message

Nathan Sidwell Oct. 15, 2019, 11:19 a.m. UTC
build_clone is recursive when applied to a template, but I found the 
control flow confusing.  this makes it clearer and moves some decls to 
their initializers.

Applying to trunk.

nathan
diff mbox series

Patch

2019-10-15  Nathan Sidwell  <nathan@acm.org>

	* class.c (build_clone): Refactor to clarify recursiveness.

Index: gcc/cp/class.c
===================================================================
--- gcc/cp/class.c	(revision 276991)
+++ gcc/cp/class.c	(working copy)
@@ -4582,14 +4582,13 @@  static tree
 build_clone (tree fn, tree name)
 {
-  tree parms;
-  tree clone;
-
   /* Copy the function.  */
-  clone = copy_decl (fn);
+  tree clone = copy_decl (fn);
   /* Reset the function name.  */
   DECL_NAME (clone) = name;
   /* Remember where this function came from.  */
   DECL_ABSTRACT_ORIGIN (clone) = fn;
-  /* Make it easy to find the CLONE given the FN.  */
+
+  /* Make it easy to find the CLONE given the FN.  Note the
+     template_result of a template will be chained this way too.  */
   DECL_CHAIN (clone) = DECL_CHAIN (fn);
   DECL_CHAIN (fn) = clone;
@@ -4600,17 +4599,16 @@  build_clone (tree fn, tree name)
       tree result = build_clone (DECL_TEMPLATE_RESULT (clone), name);
       DECL_TEMPLATE_RESULT (clone) = result;
+
       DECL_TEMPLATE_INFO (result) = copy_node (DECL_TEMPLATE_INFO (result));
       DECL_TI_TEMPLATE (result) = clone;
+
       TREE_TYPE (clone) = TREE_TYPE (result);
       return clone;
     }
-  else
-    {
-      /* Clone constraints.  */
-      if (flag_concepts)
-        if (tree ci = get_constraints (fn))
-          set_constraints (clone, copy_node (ci));
-    }
 
+  if (flag_concepts)
+    /* Clone constraints.  */
+    if (tree ci = get_constraints (fn))
+      set_constraints (clone, copy_node (ci));
 
   SET_DECL_ASSEMBLER_NAME (clone, NULL_TREE);
@@ -4624,6 +4622,5 @@  build_clone (tree fn, tree name)
     {
       DECL_VIRTUAL_P (clone) = 0;
-      if (TREE_CODE (clone) != TEMPLATE_DECL)
-	DECL_VINDEX (clone) = NULL_TREE;
+      DECL_VINDEX (clone) = NULL_TREE;
     }
 
@@ -4690,5 +4687,5 @@  build_clone (tree fn, tree name)
     DECL_CHAIN (DECL_CHAIN (DECL_ARGUMENTS (clone))) = NULL_TREE;
 
-  for (parms = DECL_ARGUMENTS (clone); parms; parms = DECL_CHAIN (parms))
+  for (tree parms = DECL_ARGUMENTS (clone); parms; parms = DECL_CHAIN (parms))
     {
       DECL_CONTEXT (parms) = clone;