Skip to content

Commit d046e8b

Browse files
committed
New issue from Tomasz: "enable_nonlocking_formatter_optimization for durations with custom rep"
1 parent bf79862 commit d046e8b

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

xml/issue4400.xml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4400" status="New">
5+
<title>`enable_nonlocking_formatter_optimization` for durations with custom rep</title>
6+
<section><sref ref="[time.format]"/></section>
7+
<submitter>Tomasz Kamiński</submitter>
8+
<date>02 Oct 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
Currently the `enable_nonlocking_formatter_optimization` is enabled for
14+
<tt>duration&lt;Rep, Ratio&gt;</tt> if it is enabled for `Rep`.
15+
</p>
16+
<blockquote><pre>
17+
template&lt;class Rep, class Period&gt;
18+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::duration&lt;Rep, Period&gt;&gt;
19+
= enable_nonlocking_formatter_optimization&lt;Rep&gt;;
20+
</pre></blockquote>
21+
<p>
22+
However, this does not take into the consideration that for custom `Rep` types, the arithmetic
23+
operations on `Rep` may also lock the stream leading to deadlock (for example log on overflow).
24+
Since they are required to handle the specifiers such as `%S` we should specialize
25+
`enable_nonlocking_formatter_optimization` only for built-in types:
26+
</p>
27+
<blockquote><pre>
28+
template&lt;class Rep, class Period&gt;
29+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::duration&lt;Rep, Period&gt;&gt;
30+
= is_arithmetic_v&lt;Rep&gt;;
31+
</pre></blockquote>
32+
<p>
33+
Furtheremore, for all types that are currently templated on `Duration` (`hh_mm_ss`, `sys_time`,
34+
`local_time`, etc.), we `enable_nonlocking_formatter_optimization` by default. This again does
35+
not take into consideration the arithmetic operations performed as duration. We should specialize
36+
`enable_nonlocking_formatter_optimization` for all of them to be enabled if
37+
`enable_nonlocking_formatter_optimization` is enabled for `duration`:
38+
</p>
39+
<blockquote><pre>
40+
template&lt;class Duration&gt;
41+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::hh_mm_ss&lt;Duration&gt;&gt;
42+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;
43+
</pre></blockquote>
44+
<p>
45+
Note, that forwarding to `enable_nonlocking_formatter_optimization` on `Duration` instead of
46+
checking `Duration::rep` allows users to specialize `enable_nonlocking_formatter_optimization` for
47+
Durations with there custom representation types.
48+
<p/>
49+
The proposed wording has recently been implemented in
50+
<a href="https://gcc.gnu.org/pipermail/libstdc++/2025-October/063758.html">gcc's libstdc++</a>.
51+
</p>
52+
</discussion>
53+
54+
<resolution>
55+
<p>
56+
This wording is relative to <paper num="N5014"/>.
57+
</p>
58+
59+
<ol>
60+
61+
<li><p>Modify <sref ref="[time.format]"/> as indicated:</p>
62+
63+
<blockquote>
64+
<p>
65+
-8- For `chrono::duration`<ins>, `chrono::hh_mm_ss`, `chrono::sys_time`, `chrono::utc_time`,
66+
`chrono::tai_time`, `chrono::gps_time`, `chrono::file_time`, `chrono::local_time`,
67+
<tt>chrono::<i>local-time-format-t</i></tt>, and `chrono::zoned_time`</ins> the library only
68+
provides the following specialization<ins>s</ins> of `enable_nonlocking_formatter_optimization`:
69+
</p>
70+
<blockquote>
71+
<pre>
72+
template&lt;class Rep, class Period&gt;
73+
constexpr bool enable_nonlocking_formatter_optimization&lt;
74+
chrono::duration&lt;Rep, Period&gt;&gt; =
75+
<del>enable_nonlocking_formatter_optimization</del><ins>is_arithmetic_v</ins>&lt;Rep&gt;;
76+
77+
<ins>template&lt;class Duration&gt;
78+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::hh_mm_ss&lt;Duration&gt;&gt;
79+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;
80+
81+
template&lt;class Duration&gt;
82+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::sys_time&lt;Duration&gt;&gt;
83+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;
84+
85+
template&lt;class Duration&gt;
86+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::utc_time&lt;Duration&gt;&gt;
87+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;
88+
89+
template&lt;class Duration&gt;
90+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::tai_time&lt;Duration&gt;&gt;
91+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;
92+
93+
template&lt;class Duration&gt;
94+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::gps_time&lt;Duration&gt;&gt;
95+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;
96+
97+
template&lt;class Duration&gt;
98+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::file_time&lt;Duration&gt;&gt;
99+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;
100+
101+
template&lt;class Duration&gt;
102+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::local_time&lt;Duration&gt;&gt;
103+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;
104+
105+
template&lt;class Duration&gt;
106+
constexpr bool enable_nonlocking_formatter_optimization&lt;chrono::<i>local-time-format-t</i>&lt;Duration&gt;&gt;
107+
= enable_nonlocking_formatter_optimization&lt;Duration&gt;;</ins>
108+
</pre>
109+
</blockquote>
110+
<p>
111+
<del>-9- For `chrono::zoned_time` the library only provides the following specialization of
112+
`enable_nonlocking_formatter_optimization`:</del>
113+
</p>
114+
<blockquote>
115+
<pre>
116+
template&lt;class Duration&gt;
117+
constexpr bool enable_nonlocking_formatter_optimization&lt;
118+
chrono::zoned_time&lt;Duration, const std::chrono::time_zone*&gt;&gt;
119+
= <del>true</del><ins>enable_nonlocking_formatter_optimization&lt;Duration&gt;</ins>;
120+
</pre>
121+
</blockquote>
122+
</blockquote>
123+
</li>
124+
</ol>
125+
126+
</resolution>
127+
128+
</issue>

0 commit comments

Comments
 (0)