From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 01A3D3857000; Mon, 20 Nov 2023 02:54:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 01A3D3857000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700448868; bh=FySaAveM+61bihLQ+yAYFDww8yYIZAZzF5NcDgs4c9o=; h=From:To:Subject:Date:From; b=Q1Z4Pn3RuniUxkUbxrhA5iNnf1aUNm07lPrBx6L/nXGAP4XVd2/8GduMfMvJsU/d4 TNsDjR2b43XXpAQaR6hUPqJYc/oc/W+sJbaEnU7u/QB1J72nP+lBhCXPKHmrGpwSAL Cv38lWKAeZGBlxJPwjxXvOQfCKWQoEUcDHbra9yc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-5605] c++: add DECL_IMPLICIT_TEMPLATE_PARM_P macro X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 0d734c79387191005c909c54c7556a88254c401b X-Git-Newrev: c51eafc1a185f7ad00820f11a7aa7bf4a82093fa Message-Id: <20231120025428.01A3D3857000@sourceware.org> Date: Mon, 20 Nov 2023 02:54:27 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c51eafc1a185f7ad00820f11a7aa7bf4a82093fa commit r14-5605-gc51eafc1a185f7ad00820f11a7aa7bf4a82093fa Author: Jason Merrill Date: Tue Oct 17 18:01:28 2023 -0400 c++: add DECL_IMPLICIT_TEMPLATE_PARM_P macro 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. Diff: --- 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(-) 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(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. */