diff mbox series

[pushed] c++: add DECL_IMPLICIT_TEMPLATE_PARM_P macro

Message ID 20231120025356.2937834-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: add DECL_IMPLICIT_TEMPLATE_PARM_P macro | expand

Commit Message

Jason Merrill Nov. 20, 2023, 2:53 a.m. UTC
Tested x86_64-pc-linux-gnu, applying to trunk.

-- 8< --

Let's use a more informative name instead of DECL_VIRTUAL_P directly.

gcc/cp/ChangeLog:

	* cp-tree.h (DECL_TEMPLATE_PARM_CHECK): New.
	(DECL_IMPLICIT_TEMPLATE_PARM_P): New.
	(decl_template_parm_check): New.
	* mangle.cc (write_closure_template_head): Use it.
	* parser.cc (synthesize_implicit_template_parm): Likewise.
	* pt.cc (template_parameters_equivalent_p): Likewise.
---
 gcc/cp/cp-tree.h | 19 +++++++++++++++++++
 gcc/cp/mangle.cc |  2 +-
 gcc/cp/parser.cc |  2 +-
 gcc/cp/pt.cc     |  3 ++-
 4 files changed, 23 insertions(+), 3 deletions(-)


base-commit: 0d734c79387191005c909c54c7556a88254c401b
diff mbox series

Patch

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index c7a1cf610c8..7b0b7c6a17e 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -677,10 +677,14 @@  template_info_decl_check (const_tree t, const char* f, int l, const char* fn)
       tree_check_failed (__t, __FILE__, __LINE__, __FUNCTION__, 0);	\
      __t; })
 
+#define DECL_TEMPLATE_PARM_CHECK(NODE) \
+  decl_template_parm_check ((NODE), __FILE__, __LINE__, __FUNCTION__)
+
 #else /* ENABLE_TREE_CHECKING */
 
 #define TEMPLATE_INFO_DECL_CHECK(NODE) (NODE)
 #define THUNK_FUNCTION_CHECK(NODE) (NODE)
+#define DECL_TEMPLATE_PARM_CHECK(NODE) (NODE)
 
 #endif /* ENABLE_TREE_CHECKING */
 
@@ -3577,6 +3581,11 @@  struct GTY(()) lang_decl {
    need.  But we want a more descriptive name.  */
 #define DECL_VTABLE_OR_VTT_P(NODE) DECL_VIRTUAL_P (VAR_DECL_CHECK (NODE))
 
+/* 1 iff a _DECL for a template parameter came from
+   synthesize_implicit_template_parm.  */
+#define DECL_IMPLICIT_TEMPLATE_PARM_P(NODE) \
+  DECL_VIRTUAL_P (DECL_TEMPLATE_PARM_CHECK (NODE))
+
 /* 1 iff FUNCTION_TYPE or METHOD_TYPE has a ref-qualifier (either & or &&). */
 #define FUNCTION_REF_QUALIFIED(NODE) \
   TREE_LANG_FLAG_4 (FUNC_OR_METHOD_CHECK (NODE))
@@ -5057,6 +5066,16 @@  get_vec_init_expr (tree t)
        || TREE_CODE (NODE) == TYPE_DECL		\
        || TREE_CODE (NODE) == TEMPLATE_DECL))
 
+#if ENABLE_TREE_CHECKING
+inline tree
+decl_template_parm_check (const_tree t, const char *f, int l, const char *fn)
+{
+  if (!DECL_TEMPLATE_PARM_P (t))
+    tree_check_failed (t, f, l, fn, 0);
+  return const_cast<tree>(t);
+}
+#endif
+
 /* Nonzero for a raw template parameter node.  */
 #define TEMPLATE_PARM_P(NODE)					\
   (TREE_CODE (NODE) == TEMPLATE_TYPE_PARM			\
diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc
index afa68da871c..5137305ed07 100644
--- a/gcc/cp/mangle.cc
+++ b/gcc/cp/mangle.cc
@@ -1744,7 +1744,7 @@  write_closure_template_head (tree tmpl)
 	continue;
       parm = TREE_VALUE (parm);
 
-      if (DECL_VIRTUAL_P (parm))
+      if (DECL_IMPLICIT_TEMPLATE_PARM_P (parm))
 	// A synthetic parm, we're done.
 	break;
 
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index d1104336215..f556b8f3c01 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -50895,7 +50895,7 @@  synthesize_implicit_template_parm  (cp_parser *parser, tree constr)
      Note that DECL_ARTIFICIAL is used elsewhere for template
      parameters.  */
   if (TREE_VALUE (new_parm) != error_mark_node)
-    DECL_VIRTUAL_P (TREE_VALUE (new_parm)) = true;
+    DECL_IMPLICIT_TEMPLATE_PARM_P (TREE_VALUE (new_parm)) = true;
 
   tree new_decl = get_local_decls ();
   if (non_type)
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 324f6f01555..1de9d3eb44f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -3359,7 +3359,8 @@  template_parameters_equivalent_p (const_tree parm1, const_tree parm2)
   /* ... one parameter was introduced by a parameter declaration, then
      both are. This case arises as a result of eagerly rewriting declarations
      during parsing.  */
-  if (DECL_VIRTUAL_P (decl1) != DECL_VIRTUAL_P (decl2))
+  if (DECL_IMPLICIT_TEMPLATE_PARM_P (decl1)
+      != DECL_IMPLICIT_TEMPLATE_PARM_P (decl2))
     return false;
 
   /* ... if either declares a pack, they both do.  */