Open frederick-vs-ja opened 1 year ago
I discuss something along these lines here: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2268r0.html#constexpr_to_consteval
I think the idea can work, but there's a need for someone to test it, and to describe the behavior differences between consteval and constexpr in these cases.
I guess I've made some tests and an incomplete conclusion for the differences.
consteval
and immediate-escalation make the function only callable in restrict contexts, while constexpr
doesn't. Sometimes the restriction might be considered overly strict.
I think the most counterintuitive affection is that if we make std::allocator
and basic_string
to freestanding while marking allocator::allocate
etc. consteval
(we can establish the // freestanding-consteval
notion for such a requirement), then a string
cannot be manipulated at the runtime even if one can guarantee that the contents always fit into the SSO buffer.
Moreover...
stable_sort
and its friends (made constexpr
in C++26 by P2652R1) freestanding-consteval.constexpr
but throwing functions are marked // freestanding-deleted
in current papers. IMO it may be better to change them to // freestanding-consteval
, because
In the core wording, perhaps we can make currently allowed forms of new
- and delete
-expressions (implementation-definedly) immediate-escalating under freestanding implementations, but
new
-expressions ~are allowed in constant evaluation in the future, they~ shouldn't be immediate-escalating.Edit: P2747 addresses non-allocating placement new
-expressions. As a result, they shouldn't be immediate-escalating.
Edit: P3295R0 addresses most of library part of this issue.
It seems that we can make
std::allocator
and its friends freestanding, with allowing theallocate
etc. member functions to beconsteval
for freestanding implementations.Thanks to P2564R3, once the
allocate
and its friends arestd::allocator
are madeconsteval
, allocation and deallocation in the downstream facilities (std::vector
,std::string
, etc.) would become only usable in constant evaluation, which avoids touching the runtime heap.Proof-by-concept example: ~(although clang is a bit buggy at this moment)~