From a112ad3b1acb0a80b719c9f424ec367071bbf91b Mon Sep 17 00:00:00 2001
From: Barry Revzin
Date: Sun, 10 Nov 2024 21:15:42 -0600
Subject: [PATCH] Improving wording, adding example
---
3496_immediate_escalating/Makefile | 2 +
.../immediate-escalating.md | 51 ++++++++++++++++-
3496_immediate_escalating/p3496r0.html | 55 ++++++++++++++++++-
3 files changed, 106 insertions(+), 2 deletions(-)
create mode 100644 3496_immediate_escalating/Makefile
diff --git a/3496_immediate_escalating/Makefile b/3496_immediate_escalating/Makefile
new file mode 100644
index 00000000..a9e1e4fa
--- /dev/null
+++ b/3496_immediate_escalating/Makefile
@@ -0,0 +1,2 @@
+p3496r0.html : immediate-escalating.md
+include ../md/mpark-wg21.mk
diff --git a/3496_immediate_escalating/immediate-escalating.md b/3496_immediate_escalating/immediate-escalating.md
index 09df1fb5..d70ecf5b 100644
--- a/3496_immediate_escalating/immediate-escalating.md
+++ b/3496_immediate_escalating/immediate-escalating.md
@@ -79,7 +79,7 @@ Here also, the call to `id(x)` internally isn't a constant expression, but `A(42
# Proposal
-Change the rules around what constitutes an immediate-escalating expression such that we only consider a consteval call to "bubble up" if there isn't simply a larger expression that already.
+Change the rules around what constitutes an immediate-escalating expression such that we only consider a consteval call to "bubble up" if it isn't already enclosed in a constant expression.
## Implementation Experience
@@ -136,4 +136,53 @@ Replace that entirely with (note that *consteval-only* will be extended by [@P29
* [#.#]{.pnum} it is not in an immediate function context, and
* [#.#]{.pnum} it is a constant expression.
:::
+:::
+
+And extend the example:
+
+::: std
+::: example9
+```diff
+ struct A {
+ int x;
+ int y = id(x);
+ };
+
+ template
+ constexpr int k(int) { // k is not an immediate function because A(42) is a
+ return A(42).y; // constant expression and thus not immediate-escalating
+ }
+
++ struct unique_ptr {
++ int* p;
++ constexpr unique_ptr(int i) : p(new int(i)) { }
++ constexpr ~unique_ptr() { delete p; }
++ constexpr int deref() const { return *p; }
++ };
++
++ consteval unique_ptr make_unique(int i) {
++ return unique_ptr(i);
++ }
++
++ constexpr int very_fancy_id(int i) {
++ return unique_ptr(121).deref(); // OK, make_unique(121) is consteval-only but it is not
++ // immediate-escalating because make_unique(121).deref()
++ // is a constant expression.
++
++ }
++
++ static_assert(very_fancy_id(121) == 121);
+```
+:::
+:::
+
+## Feature-Test Macro
+
+Bump `__cpp_consteval` in [cpp.predefined]{.sref}:
+
+::: std
+```diff
+- __cpp_consteval @[202211L]{.diffdel}@
++ __cpp_consteval @[20XXXXL]{.diffins}@
+```
:::
\ No newline at end of file
diff --git a/3496_immediate_escalating/p3496r0.html b/3496_immediate_escalating/p3496r0.html
index 8828ab36..a22a3f16 100644
--- a/3496_immediate_escalating/p3496r0.html
+++ b/3496_immediate_escalating/p3496r0.html
@@ -600,6 +600,8 @@ Contents
2.1 Implementation
Experience
2.2 Wording
+2.3 Feature-Test
+Macro
3 References
@@ -694,7 +696,7 @@
Implementation Experience
Thanks to Jason Merrill for implementing this proposal, suggesting I
split it off from [P3032R2], and giving wording help.
@@ -787,6 +789,57 @@
+
And extend the example:
+
+
+
+
[ Example 9:
+
+
struct A {
+ int x;
+ int y = id(x);
+ };
+
+ template<class T>
+ constexpr int k(int) { // k<int> is not an immediate function because A(42) is a
+ return A(42).y; // constant expression and thus not immediate-escalating
+ }
+
++ struct unique_ptr {
++ int* p;
++ constexpr unique_ptr(int i) : p(new int(i)) { }
++ constexpr ~unique_ptr() { delete p; }
++ constexpr int deref() const { return *p; }
++ };
++
++ consteval unique_ptr make_unique(int i) {
++ return unique_ptr(i);
++ }
++
++ constexpr int very_fancy_id(int i) {
++ return unique_ptr(121).deref(); // OK, make_unique(121) is consteval-only but it is not
++ // immediate-escalating because make_unique(121).deref()
++ // is a constant expression.
++
++ }
++
++ static_assert(very_fancy_id(121) == 121);
+
+
— end example ]
+
+
+
+ Feature-Test Macro
+Bump __cpp_consteval
in
+15.11 [cpp.predefined]:
+
+
+
+
- __cpp_consteval 202211L
++ __cpp_consteval 20XXXXL
+
+
+
References