diff options
author | Nathan Sidwell <nathan@acm.org> | 2020-05-14 07:33:13 -0700 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2020-05-14 07:33:13 -0700 |
commit | f497e36ae56f0f22b1d60171509c75f7b11f8663 (patch) | |
tree | b7aeb392fc50b3e5dd27823374d7cab4166888a4 | |
parent | ddbaab134ca4603f7d4ac0d1646f40f9c13405ff (diff) | |
download | gcc-f497e36ae56f0f22b1d60171509c75f7b11f8663.zip gcc-f497e36ae56f0f22b1d60171509c75f7b11f8663.tar.gz gcc-f497e36ae56f0f22b1d60171509c75f7b11f8663.tar.bz2 |
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.
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/pt.c | 70 |
2 files changed, 37 insertions, 36 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9dd04d2..bcae21c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2020-05-14 Nathan Sidwell <nathan@acm.org> + * 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 4517147..5ca659e 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; |