From f497e36ae56f0f22b1d60171509c75f7b11f8663 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 14 May 2020 07:33:13 -0700 Subject: [PATCH] c++: Simplify tsubst_template_decl tsubst_template_decl's control flow was also confusing. This reorders and flattens some of the conditionals. * pt.c (tsubst_template_decl): Reorder and commonize some control paths. --- gcc/cp/ChangeLog | 3 +++ gcc/cp/pt.c | 70 +++++++++++++++++++++++------------------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9dd04d24f19..bcae21c0d39 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2020-05-14 Nathan Sidwell + * pt.c (tsubst_template_decl): Reorder and commonize some control + paths. + * pt.c (tsubst_friend_function): Simplify control flow. * pt.c (lookup_template_class_1): Remove unnecessary else by diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4517147c8aa..5ca659e9f28 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14031,52 +14031,50 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, = tsubst_template_parms (DECL_TEMPLATE_PARMS (t), args, complain); - if (TREE_CODE (decl) == TYPE_DECL - && !TYPE_DECL_ALIAS_P (decl)) + bool class_p = false; + tree inner = decl; + ++processing_template_decl; + if (TREE_CODE (inner) == FUNCTION_DECL) + inner = tsubst_function_decl (inner, args, complain, lambda_fntype); + else { - tree new_type; - ++processing_template_decl; - new_type = tsubst (TREE_TYPE (t), args, complain, in_decl); - --processing_template_decl; - if (new_type == error_mark_node) - return error_mark_node; + if (TREE_CODE (inner) == TYPE_DECL && !TYPE_DECL_ALIAS_P (inner)) + { + class_p = true; + inner = TREE_TYPE (inner); + } + inner = tsubst (inner, args, complain, in_decl); + } + --processing_template_decl; + if (inner == error_mark_node) + return error_mark_node; - TREE_TYPE (r) = new_type; + if (class_p) + { /* For a partial specialization, we need to keep pointing to the primary template. */ if (!DECL_TEMPLATE_SPECIALIZATION (t)) - CLASSTYPE_TI_TEMPLATE (new_type) = r; - DECL_TEMPLATE_RESULT (r) = TYPE_MAIN_DECL (new_type); - DECL_TI_ARGS (r) = CLASSTYPE_TI_ARGS (new_type); - DECL_CONTEXT (r) = TYPE_CONTEXT (new_type); + CLASSTYPE_TI_TEMPLATE (inner) = r; + + DECL_TI_ARGS (r) = CLASSTYPE_TI_ARGS (inner); + inner = TYPE_MAIN_DECL (inner); + } + else if (lambda_fntype) + { + tree args = template_parms_to_args (DECL_TEMPLATE_PARMS (r)); + DECL_TEMPLATE_INFO (inner) = build_template_info (r, args); } else { - tree new_decl; - ++processing_template_decl; - if (TREE_CODE (decl) == FUNCTION_DECL) - new_decl = tsubst_function_decl (decl, args, complain, lambda_fntype); - else - new_decl = tsubst (decl, args, complain, in_decl); - --processing_template_decl; - if (new_decl == error_mark_node) - return error_mark_node; - - DECL_TEMPLATE_RESULT (r) = new_decl; - TREE_TYPE (r) = TREE_TYPE (new_decl); - DECL_CONTEXT (r) = DECL_CONTEXT (new_decl); - if (lambda_fntype) - { - tree args = template_parms_to_args (DECL_TEMPLATE_PARMS (r)); - DECL_TEMPLATE_INFO (new_decl) = build_template_info (r, args); - } - else - { - DECL_TI_TEMPLATE (new_decl) = r; - DECL_TI_ARGS (r) = DECL_TI_ARGS (new_decl); - } + if (TREE_CODE (decl) != TYPE_DECL || !TYPE_DECL_ALIAS_P (decl)) + DECL_TI_TEMPLATE (inner) = r; + DECL_TI_ARGS (r) = DECL_TI_ARGS (inner); } + DECL_TEMPLATE_RESULT (r) = inner; + TREE_TYPE (r) = TREE_TYPE (inner); + DECL_CONTEXT (r) = DECL_CONTEXT (inner); + DECL_TEMPLATE_INSTANTIATIONS (r) = NULL_TREE; DECL_TEMPLATE_SPECIALIZATIONS (r) = NULL_TREE; -- 2.30.2