GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc/contracts

C++/Contracts: Assertion predicate re-invoking constexpr function [PR125459]

Fixes C++ contract assertions to correctly handle re-invoked constexpr functions during constant evaluation.

This commit resolves an issue in GCC’s C++ contract implementation where re-invoking a constexpr function within a contract assertion or [[assume]] predicate during constant evaluation led to errors. The constexpr_global_ctx::put_value function has been updated to correctly handle void_list_node entries, preventing them from being treated as state modifications.

In Details

GCC's constexpr evaluation in cp/constexpr.cc for contracts stored results in constexpr_global_ctx. A void_list_node was used to mark the end of a function's lifetime within this context. Re-invoking a constexpr function from a contract assertion or [[assume]] predicate would find this void_list_node and incorrectly trigger modification tracking. This patch modifies put_value to ignore void_list_node for tracking purposes, resolving PR125459.

For Context
constexpr
A C++ keyword that indicates a function or variable can be evaluated at compile time.
contracts
A feature in C++ (and other languages) that allows specifying pre-conditions, post-conditions, and assertions for functions to improve code correctness and documentation.
constant evaluation
The process of evaluating expressions or function calls at compile time, typically for constexpr entities.
void_list_node
An internal representation used in GCC's constexpr evaluation to mark the end of a variable's lifetime within the evaluation context.
[[assume]]
A C++ attribute that suggests a condition is true, allowing the compiler to perform more aggressive optimizations based on that assumption.
Filed Under: c++contractsconstexprcompilerbugfix