Skip to content

Commit

Permalink
New issue from Jiang An: "std::formatter specializations should be co…
Browse files Browse the repository at this point in the history
…nsistently restricted to supported character types"
  • Loading branch information
Dani-Hub committed Oct 21, 2023
1 parent f45ab74 commit 949c4e4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions xml/issue3997.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version='1.0' encoding='utf-8' standalone='no'?>
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">

<issue num="3997" status="New">
<title><tt>std::formatter</tt> specializations should be consistently restricted to supported character types</title>
<section><sref ref="[format.syn]"/><sref ref="[time.syn]"/><sref ref="[thread.thread.id]"/></section>
<submitter>Jiang An</submitter>
<date>15 Oct 2023</date>
<priority>99</priority>

<discussion>
<p>
<sref ref="[format.formatter.spec]"/>/2 requires some <tt>std::formatter</tt> specializations are only enabled
for character types <tt>char</tt> and <tt>wchar_t</tt>. But for specializations that are explicitly shown in
the synopses (<sref ref="[format.syn]"/>, <sref ref="[time.syn]"/>, and <sref ref="[thread.thread.id]"/>),
there is no such restrictions for <tt>charT</tt>. The difference may be observable via the <tt>std::formattable</tt>
concept, e.g. <tt>std::formattable&lt;std::chrono::second, char8_t&gt;</tt> is currently satisfied, even though
there would be a hard error during formatting due to <tt><i>STATICALLY-WIDEN</i></tt>.
<p/>
Perhaps we should introduce an exposition-only concept that is only satisfied (and modeled) by <tt>char</tt> and
<tt>wchar_t</tt> for now, and constrain the <tt>charT</tt> template parameter of all <tt>std::formatter</tt>
specializations that are explicitly mentioned in synopses with that concept. This is what libc++ currently
implements (e.g. the
<a href="https://github.com/llvm/llvm-project/blob/6dfea561ba96974b205c31546c5e2069429c75b1/libcxx/include/__format/concepts.h#L32-L38"><tt>__fmt_char_type</tt></a>
concept and <a href="https://github.com/llvm/llvm-project/blob/main/libcxx/include/__chrono/formatter.h#L580-L825">its
usage in <tt>&lt;chrono&gt;</tt></a>).
</p>
</discussion>

<resolution>
</resolution>

</issue>

0 comments on commit 949c4e4

Please sign in to comment.