C++/Contracts handles constexpr modification correctly
Fixes C++ contracts to correctly evaluate constexpr expressions, preventing incorrect modifications during diagnostic re-evaluation.
This change revises how constexpr evaluations are handled within C++ contracts. Previously, the modifiable_tracker incorrectly blocked predicate evaluations from modifying objects, which is not the standard’s intent for constant initialization. The fix ensures that re-evaluations for diagnostics properly simulate the ‘ignore’ semantic and can succeed even if initial trial evaluations fail due to modification.
In Details
The constexpr evaluation logic in GCC's C++ front-end, particularly around contract checking, has been refined. The modifiable_tracker was preventing modifications during predicate evaluation, which is incorrect for determining constexpr initialization (which uses an 'ignore' semantic). This commit adjusts the tracker to better align with the standard's behavior, allowing re-evaluations for diagnostics to proceed correctly and pass where they previously might have failed due to spurious modification checks.
- constexpr
- A C++ keyword indicating that a variable or function can be evaluated at compile time. This enables certain optimizations and compile-time checks.
- C++ contracts
- A feature (primarily C++20 and later) that allows developers to specify preconditions, postconditions, and invariants for functions. These can be checked at runtime or compile time.
- modifiable_tracker
- An internal mechanism within the C++ compiler that tracks whether objects are being modified during specific evaluations, particularly relevant for
constexprand contract checks.