|
| 1 | +<pre class='metadata'> |
| 2 | +Title: Rename `std::runtime_format` |
| 3 | +Shortname: P3953 |
| 4 | +Revision: 0 |
| 5 | +Audience: LEWG |
| 6 | +Status: P |
| 7 | +Group: WG21 |
| 8 | +URL: |
| 9 | +Editor: Victor Zverovich, [email protected] |
| 10 | +No abstract: true |
| 11 | +Date: 2025-12-28 |
| 12 | +Markup Shorthands: markdown yes |
| 13 | +</pre> |
| 14 | + |
| 15 | +<p style="text-align: right"> |
| 16 | +There are only two hard things in Computer Science: cache invalidation and naming things.<br> |
| 17 | +— Phil Karlton |
| 18 | +</p> |
| 19 | + |
| 20 | +# Abstract # {#abstract} |
| 21 | + |
| 22 | + |
| 23 | +[[P2918]] introduced `std::runtime_format` to allow opting out of compile-time |
| 24 | +format string checks in `std::format`. Subsequently, [[P3391]] made |
| 25 | +`std::format` usable in constant evaluation. As a result, `std::runtime_format` |
| 26 | +can now be evaluated at compile time, making its name misleading. This paper |
| 27 | +proposes renaming `std::runtime_format` to `std::dynamic_format` to better |
| 28 | +reflect its semantics and avoid confusion in `constexpr `contexts. |
| 29 | + |
| 30 | + |
| 31 | +# Motivation # {#motivation} |
| 32 | + |
| 33 | +The name `std::runtime_format` was accurate when introduced in [[P2918]], as |
| 34 | +format strings were not usable in constant evaluation. However, with the |
| 35 | +adoption of `constexpr` `std::format`, the term runtime no longer reliably |
| 36 | +describes the behavior of `std::runtime_format`. |
| 37 | + |
| 38 | +Consider the following code: |
| 39 | + |
| 40 | +```c++ |
| 41 | +constexpr auto f(std::string_view fmt, int value) { |
| 42 | + return std::format(std::runtime_format(fmt), value); |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +Despite its name, `std::runtime_format` can be evaluated at compile time. |
| 47 | +This creates a semantic mismatch: |
| 48 | + |
| 49 | +- "runtime" suggests evaluation timing |
| 50 | +- The facility actually describes how the format string is obtained. |
| 51 | + |
| 52 | +The real distinction is not when formatting occurs, but how the format string |
| 53 | +is provided and validated. The term runtime conflates it with evaluation time. |
| 54 | + |
| 55 | +# Proposed Naming: `std::dynamic_format` # {#naming} |
| 56 | + |
| 57 | +The proposed name `std::dynamic_format` reflects the actual semantics: |
| 58 | + |
| 59 | +- The format string is dynamically provided |
| 60 | +- The format string is not a compile-time constant |
| 61 | +- The validation is deferred (but may still occur during constant evaluation) |
| 62 | + |
| 63 | +This aligns with existing terminology `std::format` such as dynamic format |
| 64 | +specifiers (`check_dynamic_spec`). |
| 65 | + |
| 66 | +Example with proposed name: |
| 67 | + |
| 68 | +``` |
| 69 | +constexpr auto f(std::string_view fmt, int value) { |
| 70 | + return std::format(std::runtime_format(fmt), value); |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +This reads naturally and avoids semantic contradiction. |
| 75 | + |
| 76 | +Impact on existing code {#impact} |
| 77 | +======================= |
| 78 | + |
| 79 | +If this is adopted for C++26 there will be no impact on existing code since |
| 80 | +`std::runtime_format` is a C++26 feature. |
| 81 | + |
| 82 | +<pre class=biblio> |
| 83 | +{ |
| 84 | + "P2918": { |
| 85 | + "title": "Runtime format strings II", |
| 86 | + "authors": ["Victor Zverovich"], |
| 87 | + "href": "https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2918r2.html" |
| 88 | + }, |
| 89 | + "P3391": { |
| 90 | + "title": "`constexpr std::format`", |
| 91 | + "authors": ["Barry Revzin"], |
| 92 | + "href": "https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3391r2.html" |
| 93 | + } |
| 94 | +} |
| 95 | +</pre> |
0 commit comments