aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/pt.cc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2022-09-28 09:20:27 -0700
committerNathan Sidwell <nathan@acm.org>2022-09-28 13:43:07 -0700
commit9f65eecdbef6027722e93aadf3fa6b3cc342eb4f (patch)
treef48eebe3d44d85a5326b75a3a609ebc0b3a8c5fb /gcc/cp/pt.cc
parentdb288230db55dc1ff626f46c708b555847013a41 (diff)
downloadgcc-9f65eecdbef6027722e93aadf3fa6b3cc342eb4f.zip
gcc-9f65eecdbef6027722e93aadf3fa6b3cc342eb4f.tar.gz
gcc-9f65eecdbef6027722e93aadf3fa6b3cc342eb4f.tar.bz2
c++: Add DECL_NTTP_OBJECT_P lang flag
VAR_DECLs for NTTPs need to be handled specially by module streaming, in the same manner to type info decls. This reworks their handling to allow that work to drop in. We use DECL_LANG_FLAG_5 to indicate such decls (I didn't notice template_parm_object_p, which looks at the mangled name -- anyway a bit flag on the node is better, IMHO). We break apart the creation routine, so there's now an entry point the module machinery can use directly. gcc/cp/ * cp-tree.h (DECL_NTTP_OBJECT_P): New. (template_parm_object_p): Delete. (build_template_parm_object): Declare. * cxx-pretty-print.cc (pp_cx_template_argument_list): Use DECL_NTTP_OBJECT_P. * error.cc (dump_simple_decl): Likewise. * mangle.cc (write_template_arg): Likewise. * pt.cc (template_parm_object_p): Delete. (create_template_parm_object): Separated out checking from ... (get_template_parm_object): ... this, new external entry point.
Diffstat (limited to 'gcc/cp/pt.cc')
-rw-r--r--gcc/cp/pt.cc35
1 files changed, 17 insertions, 18 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 2d83dfd..c7adaef 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -7112,16 +7112,6 @@ unify_template_argument_mismatch (bool explain_p, tree parm, tree arg)
return unify_invalid (explain_p);
}
-/* True if T is a C++20 template parameter object to store the argument for a
- template parameter of class type. */
-
-bool
-template_parm_object_p (const_tree t)
-{
- return (TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t) && DECL_NAME (t)
- && startswith (IDENTIFIER_POINTER (DECL_NAME (t)), "_ZTA"));
-}
-
/* Subroutine of convert_nontype_argument, to check whether EXPR, as an
argument for TYPE, points to an unsuitable object.
@@ -7256,16 +7246,11 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain)
}
-/* The template arguments corresponding to template parameter objects of types
- that contain pointers to members. */
-
-static GTY(()) hash_map<tree, tree> *tparm_obj_values;
-
/* Return a VAR_DECL for the C++20 template parameter object corresponding to
template argument EXPR. */
static tree
-get_template_parm_object (tree expr, tsubst_flags_t complain)
+create_template_parm_object (tree expr, tsubst_flags_t complain)
{
if (TREE_CODE (expr) == TARGET_EXPR)
expr = TARGET_EXPR_INITIAL (expr);
@@ -7283,13 +7268,27 @@ get_template_parm_object (tree expr, tsubst_flags_t complain)
/* This is no longer a compound literal. */
gcc_assert (!TREE_HAS_CONSTRUCTOR (expr));
- tree name = mangle_template_parm_object (expr);
+ return get_template_parm_object (expr, mangle_template_parm_object (expr));
+}
+
+/* The template arguments corresponding to template parameter objects of types
+ that contain pointers to members. */
+
+static GTY(()) hash_map<tree, tree> *tparm_obj_values;
+
+/* Find or build an nttp object for (already-validated) EXPR with name
+ NAME. */
+
+tree
+get_template_parm_object (tree expr, tree name)
+{
tree decl = get_global_binding (name);
if (decl)
return decl;
tree type = cp_build_qualified_type (TREE_TYPE (expr), TYPE_QUAL_CONST);
decl = create_temporary_var (type);
+ DECL_NTTP_OBJECT_P (decl) = true;
DECL_CONTEXT (decl) = NULL_TREE;
TREE_STATIC (decl) = true;
DECL_DECLARED_CONSTEXPR_P (decl) = true;
@@ -7776,7 +7775,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain)
/* Replace the argument with a reference to the corresponding template
parameter object. */
if (!val_dep_p)
- expr = get_template_parm_object (expr, complain);
+ expr = create_template_parm_object (expr, complain);
if (expr == error_mark_node)
return NULL_TREE;
}