Changes since v3 (patch is approved)
- rebased onto r16-7033-gfb6a2e3f1fa842 (includes reflection changes).
Changes since v2 (patch is approved)
- Addressed Jason's review comment
- rebased onto r16-6757-g460edeb8bea11e (includes new year (c) change).
Changes since v1
- rebased onto r16-5785-g3b30d09ac7bbf8 (includes change to default to
C++20).
--- 8< ---
This adds a scope for contract assertions as per the standard section
referenced. Split out here because it is the only part of the implementation
that touches the name lookup files.
gcc/cp/ChangeLog:
* cp-tree.h (processing_contract_condition): New.
* name-lookup.cc (cp_binding_level_descriptor): Add contract scope.
(begin_scope): Likewise.
* name-lookup.h (enum scope_kind): Add sk_contract.
Signed-off-by: Iain Sandoe <[email protected]>
---
gcc/cp/cp-tree.h | 7 +++++++
gcc/cp/name-lookup.cc | 4 +++-
gcc/cp/name-lookup.h | 2 ++
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index fdcc7480e18a..27aaecf7d4b6 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2154,6 +2154,13 @@ extern GTY(()) struct saved_scope *scope_chain;
#define processing_explicit_instantiation
scope_chain->x_processing_explicit_instantiation
#define processing_omp_trait_property_expr
scope_chain->x_processing_omp_trait_property_expr
+/* Nonzero if we are parsing the expression of a contract condition. These
+ expressions appear outside the parameter list (like a trailing return
+ type), but are potentially evaluated. */
+
+#define processing_contract_condition \
+ (scope_chain->bindings->kind == sk_contract)
+
#define in_discarded_stmt scope_chain->discarded_stmt
#define in_consteval_if_p scope_chain->consteval_if_p
#define in_expansion_stmt scope_chain->expansion_stmt
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index a1f0a0ff38e1..a510133a6130 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -4737,7 +4737,8 @@ cp_binding_level_descriptor (cp_binding_level *scope)
"template-explicit-spec-scope",
"transaction-scope",
"openmp-scope",
- "lambda-scope"
+ "lambda-scope",
+ "contract-check-scope"
};
static_assert (ARRAY_SIZE (scope_kind_names) == sk_count,
"must keep names aligned with scope_kind enum");
@@ -4828,6 +4829,7 @@ begin_scope (scope_kind kind, tree entity)
case sk_scoped_enum:
case sk_transaction:
case sk_omp:
+ case sk_contract:
case sk_stmt_expr:
case sk_lambda:
scope->keep = keep_next_level_flag;
diff --git a/gcc/cp/name-lookup.h b/gcc/cp/name-lookup.h
index 4c0ca435762b..4c167cd135c4 100644
--- a/gcc/cp/name-lookup.h
+++ b/gcc/cp/name-lookup.h
@@ -229,6 +229,8 @@ enum scope_kind {
sk_transaction, /* A synchronized or atomic statement. */
sk_omp, /* An OpenMP structured block. */
sk_lambda, /* A lambda scope. */
+ sk_contract, /* A C++26 contract-assertion scope.
+ [basic.scope.contract] */
sk_count /* Number of scope_kind enumerations. */
};
--
2.50.1 (Apple Git-155)