C++ PATCH to allow copying of local_specializations
Jason Merrill
jason@redhat.com
Tue Aug 29 19:13:00 GMT 2017
When instantiating a lambda-expression in the new model, we want to
retain the local_specializations from the enclosing function but still
be able to remember specializations local to the lambda and discard
them afterwards. With this patch a local_specialization_stack object
can start with a copy of the enclosing map.
Tested x86_64-pc-linux-gnu, applying to trunk.
-------------- next part --------------
commit aa72ed613b20715d171287c643f611b7c30b3f12
Author: Jason Merrill <jason@redhat.com>
Date: Tue Jul 11 17:32:21 2017 -0400
Support copying local_specializations.
* cp-tree.h (enum lss_policy): New.
(local_specialization_stack): Add policy parameter to default ctor.
* pt.c (local_specialization_stack): Copy local_specializations if
lss_copy.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index f0eafb3..a58e7bd 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -5117,9 +5117,10 @@ enum unification_kind_t {
// An RAII class used to create a new pointer map for local
// specializations. When the stack goes out of scope, the
// previous pointer map is restored.
+enum lss_policy { lss_blank, lss_copy };
struct local_specialization_stack
{
- local_specialization_stack ();
+ local_specialization_stack (lss_policy = lss_blank);
~local_specialization_stack ();
hash_map<tree, tree> *saved;
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 847cd68..416d17b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -77,10 +77,13 @@ static tree cur_stmt_expr;
//
// Implementation of the RAII helper for creating new local
// specializations.
-local_specialization_stack::local_specialization_stack ()
+local_specialization_stack::local_specialization_stack (lss_policy policy)
: saved (local_specializations)
{
- local_specializations = new hash_map<tree, tree>;
+ if (policy == lss_blank || !saved)
+ local_specializations = new hash_map<tree, tree>;
+ else
+ local_specializations = new hash_map<tree, tree>(*saved);
}
local_specialization_stack::~local_specialization_stack ()
More information about the Gcc-patches
mailing list