From 386c40778648fecf4807566d5254dec191d35dab Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 15 Oct 2019 11:20:06 +0000 Subject: [PATCH] [C++ PATCH] build_clone cleanup https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01069.html 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. * class.c (build_clone): Refactor to clarify recursiveness. From-SVN: r276992 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/class.c | 27 ++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7245b3ed270..a2fc0720b47 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2019-10-15 Nathan Sidwell + + * class.c (build_clone): Refactor to clarify recursiveness. + 2019-10-14 Jason Merrill PR c++/91930 - ICE with constrained inherited default ctor. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index b6afdc487e7..b9266b39e28 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -4581,16 +4581,15 @@ check_methods (tree t) 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; @@ -4599,19 +4598,18 @@ 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); DECL_CLONED_FUNCTION (clone) = fn; @@ -4623,8 +4621,7 @@ build_clone (tree fn, tree name) if (name == base_dtor_identifier) { DECL_VIRTUAL_P (clone) = 0; - if (TREE_CODE (clone) != TEMPLATE_DECL) - DECL_VINDEX (clone) = NULL_TREE; + DECL_VINDEX (clone) = NULL_TREE; } bool ctor_omit_inherited_parms_p = ctor_omit_inherited_parms (clone); @@ -4689,7 +4686,7 @@ build_clone (tree fn, tree name) if (ctor_omit_inherited_parms_p) 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; cxx_dup_lang_specific_decl (parms); -- 2.30.2