<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3993: The parse function of a BasicFormatter type needs to be constexpr</title>
<meta property="og:title" content="Issue 3993: The parse function of a BasicFormatter type needs to be constexpr">
<meta property="og:description" content="C++ library issue. Status: New">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3993.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p>
<h3 id="3993"><a href="lwg-active.html#3993">3993</a>. The <code>parse</code> function of a <i>BasicFormatter</i> type needs to be <code>constexpr</code></h3>
<p><b>Section:</b> 28.5.6.1 <a href="https://wg21.link/formatter.requirements">[formatter.requirements]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
 <b>Submitter:</b> Jiang An <b>Opened:</b> 2023-10-10 <b>Last modified:</b> 2023-10-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#formatter.requirements">issues</a> in [formatter.requirements].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
<p><b>Discussion:</b></p>
<p>
Format strings need to be checkable at compile-time since <a href="https://wg21.link/P2216R3" title=" std::format improvements">P2216R3</a>. In order to check a 
compile-time format string, the <code>parse</code> functions of the formatters need to be called. However, 
currently there is seemingly no requirement for the <code>parse</code> function to be <code>constexpr</code>, 
and hence whether a format string is correct for formatted types may be not well-defined at compile-time.
</p>

<p><i>[2023-10-30; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll.
"Should be OK to provide a non-constexpr <code>parse</code> if you only use it
with <code>std::vformat</code> and not <code>std::format</code>."
"Only the <code>std::formatter</code> specializations in the standard library
should be required to have constexpr <code>parse</code>."
"No need to require this, but a note with this text explaining when a call
to <code>parse</code> can be a constant expression might be nice."
</p>



<p id="res-3993"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4958" title=" Working Draft, Programming Languages — C++">N4958</a>.
</p>

<ol>

<li><p>Modify 28.5.6.1 <a href="https://wg21.link/formatter.requirements">[formatter.requirements]</a>, Table 73, <i>BasicFormatter</i> requirements [tab:formatter.basic] as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 73: <i>BasicFormatter</i> requirements [tab:formatter.basic]</caption>
<tr>
<th align="center">Expression</th>
<th align="center">Return type</th>
<th align="center">Requirement</th>
</tr>

<tr>
<td>
<code>g.parse(pc)</code>
</td>
<td>
<code>PC::iterator</code>
</td>
<td>
Parses <i>format-spec</i> (28.5.2 <a href="https://wg21.link/format.string">[format.string]</a>) for type <code>T</code> in the<br/>
range <code>[pc.begin(), pc.end())</code> until the first unmatched<br/>
character. Throws <code>format_error</code> unless<br/>
the whole range is parsed or the unmatched<br/>
character is <code>}</code>.<br/>
[<i>Note 1</i>: This allows formatters to emit meaningful<br/>
error messages. &mdash; <i>end note</i>]<br/>
Stores the parsed format specifiers in <code>*this</code> and<br/>
returns an iterator past the end of the parsed<br/>
range.
<ins>The expression shall be a core constant expression if <code>g</code>,<br/>
<code>pc.begin()</code>, <code>pc.end()</code>, and lvalue-to-rvalue conversion<br/>
for each element in <code>[pc.begin(), pc.end())</code> are core constant<br/>
expressions, and no exception is thrown.</ins>
</td>
</tr>

<tr>
<td colspan="3" align="center">
<code>&hellip;</code>
</td>
</tr>

</table>
</blockquote>


</li>

</ol>





</body>
</html>
