]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++, contracts: Abstract interfaces to constexpr [NFC].
authorIain Sandoe <iain@sandoe.co.uk>
Wed, 17 Sep 2025 15:28:41 +0000 (16:28 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Wed, 1 Oct 2025 21:38:59 +0000 (22:38 +0100)
We want to move to having different representations of the contract
semantic for C++26, since that wants values outside the range that
can be accommodated using the cxx2a mechanisms.  First part, abstract
the interfaces to constexpr, so that they do not see the underlying
source of data.

gcc/cp/ChangeLog:

* constexpr.cc (cxx_eval_constant_expression): Use revised
interfaces to determine if contracts are ignored and, if not,
whether they are evaluated.
* contracts.h (contract_ignored_p, contract_evaluated_p): New.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
gcc/cp/constexpr.cc
gcc/cp/contracts.h

index 6ebe6ebaef63fc38978d005a9932b9794e5bf6ba..558ef6ed4717c397b64d6e2dbc2aa8e102460f1f 100644 (file)
@@ -10162,14 +10162,13 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
     case PRECONDITION_STMT:
     case POSTCONDITION_STMT:
       {
-       contract_semantic semantic = get_contract_semantic (t);
-       if (semantic == CCS_IGNORE)
+       if (contract_ignored_p (t))
          break;
 
        if (!cxx_eval_assert (ctx, CONTRACT_CONDITION (t),
                              G_("contract predicate is false in "
                                 "constant expression"),
-                             EXPR_LOCATION (t), checked_contract_p (semantic),
+                             EXPR_LOCATION (t), contract_evaluated_p (t),
                              non_constant_p, overflow_p))
          *non_constant_p = true;
        r = void_node;
index ead07d19fb7badf3f73030a824c3bdc71a869463..54eacd9a4c5a338aa094c4af68ab414851382a10 100644 (file)
@@ -334,4 +334,19 @@ set_contract_semantic (tree t, contract_semantic semantic)
 }
 
 
+/* Will this contract be ignored.  */
+
+inline bool
+contract_ignored_p (const_tree contract)
+{
+  return (get_contract_semantic (contract) <= CCS_IGNORE);
+}
+
+/* Will this contract be evaluated?  */
+
+inline bool
+contract_evaluated_p (const_tree contract)
+{
+  return (get_contract_semantic (contract) >= CCS_NEVER);
+}
 #endif /* ! GCC_CP_CONTRACT_H */