diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-11-16 07:37:05 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-11-16 07:37:05 +0100 |
commit | 7f014022861b5b3f00be9bb32fe3fe772517ddac (patch) | |
tree | ed009c2de327bf023de96fb16d0e71d14c749985 /gcc/cp | |
parent | 7c6cd9c05efca29a1a9635b81c86cbad25bbdbbe (diff) | |
download | gcc-7f014022861b5b3f00be9bb32fe3fe772517ddac.zip gcc-7f014022861b5b3f00be9bb32fe3fe772517ddac.tar.gz gcc-7f014022861b5b3f00be9bb32fe3fe772517ddac.tar.bz2 |
c++: Allow attributes on concepts - DR 2428
The following patch adds parsing of attributes to concept definition,
allows deprecated attribute to be specified (as CONCEPT_DECL now needs
to be checked in c-family/c-attribs.cc, I had to move its declaration
from cp/*.def to c-family/*.def) and checks TREE_DEPRECATED in
build_standard_check (not sure if that is the right spot, or whether
it shouldn't be checked also for variable and function concepts and
how to write testcase coverage for that).
2022-11-16 Jakub Jelinek <jakub@redhat.com>
gcc/c-family/
* c-common.def (CONCEPT_DECL): New tree, moved here from
cp-tree.def.
* c-common.cc (c_common_init_ts): Handle CONCEPT_DECL.
* c-attribs.cc (handle_deprecated_attribute): Allow deprecated
attribute on CONCEPT_DECL.
gcc/cp/
* cp-tree.def (CONCEPT_DECL): Move to c-common.def.
* cp-objcp-common.cc (cp_common_init_ts): Don't handle CONCEPT_DECL
here.
* cp-tree.h (finish_concept_definition): Add ATTRS parameter.
* parser.cc (cp_parser_concept_definition): Parse attributes in
between identifier and =. Adjust finish_concept_definition
caller.
* pt.cc (finish_concept_definition): Add ATTRS parameter. Call
cplus_decl_attributes.
* constraint.cc (build_standard_check): If CONCEPT_DECL is
TREE_DEPRECATED, emit -Wdeprecated-declaration warnings.
gcc/testsuite/
* g++.dg/cpp2a/concepts-dr2428.C: New test.
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/constraint.cc | 2 | ||||
-rw-r--r-- | gcc/cp/cp-objcp-common.cc | 1 | ||||
-rw-r--r-- | gcc/cp/cp-tree.def | 5 | ||||
-rw-r--r-- | gcc/cp/cp-tree.h | 2 | ||||
-rw-r--r-- | gcc/cp/parser.cc | 4 | ||||
-rw-r--r-- | gcc/cp/pt.cc | 5 |
6 files changed, 10 insertions, 9 deletions
diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 3ddbd53..a113d3e 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -1396,6 +1396,8 @@ build_standard_check (tree tmpl, tree args, tsubst_flags_t complain) { gcc_assert (standard_concept_p (tmpl)); gcc_assert (TREE_CODE (tmpl) == TEMPLATE_DECL); + if (TREE_DEPRECATED (DECL_TEMPLATE_RESULT (tmpl))) + warn_deprecated_use (DECL_TEMPLATE_RESULT (tmpl), NULL_TREE); tree parms = INNERMOST_TEMPLATE_PARMS (DECL_TEMPLATE_PARMS (tmpl)); args = coerce_template_parms (parms, args, tmpl, complain); if (args == error_mark_node) diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index e4df30d..7f76f2c 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -473,7 +473,6 @@ cp_common_init_ts (void) /* New decls. */ MARK_TS_DECL_COMMON (TEMPLATE_DECL); MARK_TS_DECL_COMMON (WILDCARD_DECL); - MARK_TS_DECL_COMMON (CONCEPT_DECL); MARK_TS_DECL_NON_COMMON (USING_DECL); diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def index f83b4c5..3de8278 100644 --- a/gcc/cp/cp-tree.def +++ b/gcc/cp/cp-tree.def @@ -495,11 +495,6 @@ DEFTREECODE (OMP_DEPOBJ, "omp_depobj", tcc_statement, 2) /* Extensions for Concepts. */ -/* Concept definition. This is not entirely different than a VAR_DECL - except that a) it must be a template, and b) doesn't have the wide - range of value and linkage options available to variables. */ -DEFTREECODE (CONCEPT_DECL, "concept_decl", tcc_declaration, 0) - /* Used to represent information associated with constrained declarations. */ DEFTREECODE (CONSTRAINT_INFO, "constraint_info", tcc_exceptional, 0) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 8c9beb8..07f96ea 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -8322,7 +8322,7 @@ struct diagnosing_failed_constraint extern cp_expr finish_constraint_or_expr (location_t, cp_expr, cp_expr); extern cp_expr finish_constraint_and_expr (location_t, cp_expr, cp_expr); extern cp_expr finish_constraint_primary_expr (cp_expr); -extern tree finish_concept_definition (cp_expr, tree); +extern tree finish_concept_definition (cp_expr, tree, tree); extern tree combine_constraint_expressions (tree, tree); extern tree append_constraint (tree, tree); extern tree get_constraints (const_tree); diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index e402183..c5929a6 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -29672,6 +29672,8 @@ cp_parser_concept_definition (cp_parser *parser) return NULL_TREE; } + tree attrs = cp_parser_attributes_opt (parser); + if (!cp_parser_require (parser, CPP_EQ, RT_EQ)) { cp_parser_skip_to_end_of_statement (parser); @@ -29688,7 +29690,7 @@ cp_parser_concept_definition (cp_parser *parser) but continue as if it were. */ cp_parser_consume_semicolon_at_end_of_statement (parser); - return finish_concept_definition (id, init); + return finish_concept_definition (id, init, attrs); } // -------------------------------------------------------------------------- // diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index e6017b3..0310e38 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -28928,7 +28928,7 @@ placeholder_type_constraint_dependent_p (tree t) the TEMPLATE_DECL. */ tree -finish_concept_definition (cp_expr id, tree init) +finish_concept_definition (cp_expr id, tree init, tree attrs) { gcc_assert (identifier_p (id)); gcc_assert (processing_template_decl); @@ -28962,6 +28962,9 @@ finish_concept_definition (cp_expr id, tree init) DECL_CONTEXT (decl) = current_scope (); DECL_INITIAL (decl) = init; + if (attrs) + cplus_decl_attributes (&decl, attrs, 0); + set_originating_module (decl, false); /* Push the enclosing template. */ |