From eaff878db1e44867fe734adb948f54dbc284ac5f Mon Sep 17 00:00:00 2001 From: Volker Reichelt Date: Mon, 5 Dec 2005 18:01:05 +0000 Subject: [PATCH] Backport: 2005-10-13 Mark Mitchell PR c++/22352 * pt.c (tsubst_template_parms): Set processing_template_decl while processing the parameters. (tsubst_decl): Set processing_template_decl when substituting into a TEMPLATE_DECL. * g++.dg/template/friend38.C: New test. From-SVN: r108066 --- gcc/cp/ChangeLog | 11 +++++++++ gcc/cp/pt.c | 30 +++++++++++++++++++----- gcc/testsuite/ChangeLog | 8 +++++++ gcc/testsuite/g++.dg/template/friend38.C | 12 ++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/friend38.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ae8cad7bf6ba..e9767a957fc0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,14 @@ +2005-12-05 Volker Reichelt + + Backport: + 2005-10-13 Mark Mitchell + + PR c++/22352 + * pt.c (tsubst_template_parms): Set processing_template_decl while + processing the parameters. + (tsubst_decl): Set processing_template_decl when substituting into + a TEMPLATE_DECL. + 2005-12-05 Volker Reichelt Backport: diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index b547cefbda9a..e916c3786d73 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5785,6 +5785,12 @@ tsubst_template_parms (tree parms, tree args, tsubst_flags_t complain) tree r = NULL_TREE; tree* new_parms; + /* When substituting into a template, we must set + PROCESSING_TEMPLATE_DECL as the template parameters may be + dependent if they are based on one-another, and the dependency + predicates are short-circuit outside of templates. */ + ++processing_template_decl; + for (new_parms = &r; TMPL_PARMS_DEPTH (parms) > TMPL_ARGS_DEPTH (args); new_parms = &(TREE_CHAIN (*new_parms)), @@ -5814,6 +5820,8 @@ tsubst_template_parms (tree parms, tree args, tsubst_flags_t complain) new_vec, NULL_TREE); } + --processing_template_decl; + return r; } @@ -5999,8 +6007,14 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain) : DECL_TI_ARGS (DECL_TEMPLATE_RESULT (t)); tree full_args; + /* Because this is a template, the arguments will still be + dependent, even after substitution. If + PROCESSING_TEMPLATE_DECL is not set, the dependency + predicates will short-circuit. */ + ++processing_template_decl; full_args = tsubst_template_args (tmpl_args, args, complain, in_decl); + --processing_template_decl; /* tsubst_template_args doesn't copy the vector if nothing changed. But, *something* should have @@ -6032,15 +6046,14 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain) break; } - DECL_CONTEXT (r) - = tsubst_aggr_type (DECL_CONTEXT (t), args, - complain, in_decl, - /*entering_scope=*/1); DECL_TEMPLATE_INFO (r) = build_tree_list (t, args); if (TREE_CODE (decl) == TYPE_DECL) { - tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl); + 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; @@ -6048,10 +6061,14 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain) 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); } else { - tree new_decl = tsubst (decl, args, complain, in_decl); + tree new_decl; + ++processing_template_decl; + new_decl = tsubst (decl, args, complain, in_decl); + --processing_template_decl; if (new_decl == error_mark_node) return error_mark_node; @@ -6059,6 +6076,7 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain) DECL_TI_TEMPLATE (new_decl) = r; TREE_TYPE (r) = TREE_TYPE (new_decl); DECL_TI_ARGS (r) = DECL_TI_ARGS (new_decl); + DECL_CONTEXT (r) = DECL_CONTEXT (new_decl); } SET_DECL_IMPLICIT_INSTANTIATION (r); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7063568386a5..919ebd5fdad7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2005-12-05 Volker Reichelt + + Backport: + 2005-10-13 Mark Mitchell + + PR c++/22352 + * g++.dg/template/friend38.C: New test. + 2005-12-05 Volker Reichelt Backport: diff --git a/gcc/testsuite/g++.dg/template/friend38.C b/gcc/testsuite/g++.dg/template/friend38.C new file mode 100644 index 000000000000..41faf79110cf --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend38.C @@ -0,0 +1,12 @@ +// PR c++/22352 + +template +class s +{ + typedef int d; + template + friend class t; +}; + +s t1; + -- 2.47.2