I've committed this patch, which is the tidying up I've done for the
67273 and 79253 patch on its way.
instantiate_decl's cleanup is a little untidy because of some 'goto out'
statements, that jump into the middle of the cleanup.
1) finally make defer_ok a bool
2) sort the state restoration to be in reverse order.
3) move the omp_privatization restoration to just before the out label.
(it's saved after the last goto).
nathan
--
Nathan Sidwell
2017-01-31 Nathan Sidwell <nat...@acm.org>
* cp-tree.h (instantiate_decl): Make defer_ok bool.
* pt.c: Fix instantiate_decl calls to pass true/false not 0/1
(instantiate_decl): Simplify and reorder state saving and restoration.
Index: cp/cp-tree.h
===================================================================
--- cp/cp-tree.h (revision 245065)
+++ cp/cp-tree.h (working copy)
@@ -6189,7 +6189,7 @@ extern void do_decl_instantiation (tree
extern void do_type_instantiation (tree, tree, tsubst_flags_t);
extern bool always_instantiate_p (tree);
extern void maybe_instantiate_noexcept (tree);
-extern tree instantiate_decl (tree, int, bool);
+extern tree instantiate_decl (tree, bool, bool);
extern int comp_template_parms (const_tree, const_tree);
extern bool uses_parameter_packs (tree);
extern bool template_parameter_pack_p (const_tree);
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 245065)
+++ cp/pt.c (working copy)
@@ -10676,7 +10676,7 @@ instantiate_class_template_1 (tree type)
{
/* Set function_depth to avoid garbage collection. */
++function_depth;
- instantiate_decl (decl, false, false);
+ instantiate_decl (decl, /*defer_ok=*/false, false);
--function_depth;
}
@@ -16022,7 +16022,8 @@ tsubst_expr (tree t, tree args, tsubst_f
complete_type (tmp);
for (fn = TYPE_METHODS (tmp); fn; fn = DECL_CHAIN (fn))
if (!DECL_ARTIFICIAL (fn))
- instantiate_decl (fn, /*defer_ok*/0, /*expl_inst_class*/false);
+ instantiate_decl (fn, /*defer_ok=*/false,
+ /*expl_inst_class=*/false);
}
break;
@@ -21946,7 +21947,7 @@ do_decl_instantiation (tree decl, tree s
check_explicit_instantiation_namespace (result);
mark_decl_instantiated (result, extern_p);
if (! extern_p)
- instantiate_decl (result, /*defer_ok=*/1,
+ instantiate_decl (result, /*defer_ok=*/true,
/*expl_inst_class_mem_p=*/false);
}
@@ -21984,7 +21985,7 @@ instantiate_class_member (tree decl, int
{
mark_decl_instantiated (decl, extern_p);
if (! extern_p)
- instantiate_decl (decl, /*defer_ok=*/1,
+ instantiate_decl (decl, /*defer_ok=*/true,
/*expl_inst_class_mem_p=*/true);
}
@@ -22405,15 +22406,14 @@ maybe_instantiate_noexcept (tree fn)
}
/* Produce the definition of D, a _DECL generated from a template. If
- DEFER_OK is nonzero, then we don't have to actually do the
+ DEFER_OK is true, then we don't have to actually do the
instantiation now; we just have to do it sometime. Normally it is
an error if this is an explicit instantiation but D is undefined.
- EXPL_INST_CLASS_MEM_P is true iff D is a member of an
- explicitly instantiated class template. */
+ EXPL_INST_CLASS_MEM_P is true iff D is a member of an explicitly
+ instantiated class template. */
tree
-instantiate_decl (tree d, int defer_ok,
- bool expl_inst_class_mem_p)
+instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
{
tree tmpl = DECL_TI_TEMPLATE (d);
tree gen_args;
@@ -22428,8 +22428,6 @@ instantiate_decl (tree d, int defer_ok,
int saved_inhibit_evaluation_warnings = c_inhibit_evaluation_warnings;
bool external_p;
bool deleted_p;
- tree fn_context;
- bool nested = false;
/* This function should only be used to instantiate templates for
functions and static member variables. */
@@ -22444,7 +22442,7 @@ instantiate_decl (tree d, int defer_ok,
if the variable has a constant value the referring expression can
take advantage of that fact. */
if (VAR_P (d))
- defer_ok = 0;
+ defer_ok = false;
/* Don't instantiate cloned functions. Instead, instantiate the
functions they cloned. */
@@ -22668,6 +22666,8 @@ instantiate_decl (tree d, int defer_ok,
goto out;
}
+ bool nested;
+ tree fn_context;
fn_context = decl_function_context (d);
nested = (current_function_decl != NULL_TREE);
vec<tree> omp_privatization_save;
@@ -22854,16 +22854,16 @@ instantiate_decl (tree d, int defer_ok,
else if (nested)
pop_function_context ();
-out:
- input_location = saved_loc;
- cp_unevaluated_operand = saved_unevaluated_operand;
- c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings;
- pop_deferring_access_checks ();
- pop_tinst_level ();
if (nested)
restore_omp_privatization_clauses (omp_privatization_save);
+out:
+ pop_deferring_access_checks ();
timevar_pop (TV_TEMPLATE_INST);
+ pop_tinst_level ();
+ input_location = saved_loc;
+ cp_unevaluated_operand = saved_unevaluated_operand;
+ c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings;
return d;
}
@@ -22919,7 +22919,7 @@ instantiate_pending_templates (int retri
fn = TREE_CHAIN (fn))
if (! DECL_ARTIFICIAL (fn))
instantiate_decl (fn,
- /*defer_ok=*/0,
+ /*defer_ok=*/false,
/*expl_inst_class_mem_p=*/false);
if (COMPLETE_TYPE_P (instantiation))
reconsider = 1;
@@ -22934,7 +22934,7 @@ instantiate_pending_templates (int retri
{
instantiation
= instantiate_decl (instantiation,
- /*defer_ok=*/0,
+ /*defer_ok=*/false,
/*expl_inst_class_mem_p=*/false);
if (DECL_TEMPLATE_INSTANTIATED (instantiation))
reconsider = 1;