Skip to content

Commit 2f9da36

Browse files
author
github-actions
committed
Automatic update from GitHub Actions workflow
1 parent 93cf333 commit 2f9da36

22 files changed

+421
-44
lines changed

issue4257.html

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Issue 4257: Stream insertion for chrono::local_time should be constrained</title>
6+
<meta property="og:title" content="Issue 4257: Stream insertion for chrono::local_time should be constrained">
7+
<meta property="og:description" content="C++ library issue. Status: New">
8+
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4257.html">
9+
<meta property="og:type" content="website">
10+
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
11+
<meta property="og:image:alt" content="C++ logo">
12+
<style>
13+
p {text-align:justify}
14+
li {text-align:justify}
15+
pre code.backtick::before { content: "`" }
16+
pre code.backtick::after { content: "`" }
17+
blockquote.note
18+
{
19+
background-color:#E0E0E0;
20+
padding-left: 15px;
21+
padding-right: 15px;
22+
padding-top: 1px;
23+
padding-bottom: 1px;
24+
}
25+
ins {background-color:#A0FFA0}
26+
del {background-color:#FFA0A0}
27+
table.issues-index { border: 1px solid; border-collapse: collapse; }
28+
table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
29+
table.issues-index td { padding: 4px; border: 1px solid; }
30+
table.issues-index td:nth-child(1) { text-align: right; }
31+
table.issues-index td:nth-child(2) { text-align: left; }
32+
table.issues-index td:nth-child(3) { text-align: left; }
33+
table.issues-index td:nth-child(4) { text-align: left; }
34+
table.issues-index td:nth-child(5) { text-align: center; }
35+
table.issues-index td:nth-child(6) { text-align: center; }
36+
table.issues-index td:nth-child(7) { text-align: left; }
37+
table.issues-index td:nth-child(5) span.no-pr { color: red; }
38+
@media (prefers-color-scheme: dark) {
39+
html {
40+
color: #ddd;
41+
background-color: black;
42+
}
43+
ins {
44+
background-color: #225522
45+
}
46+
del {
47+
background-color: #662222
48+
}
49+
a {
50+
color: #6af
51+
}
52+
a:visited {
53+
color: #6af
54+
}
55+
blockquote.note
56+
{
57+
background-color: rgba(255, 255, 255, .10)
58+
}
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
<hr>
64+
<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>
65+
<h3 id="4257"><a href="lwg-active.html#4257">4257</a>. Stream insertion for <code class='backtick'>chrono::local_time</code> should be constrained</h3>
66+
<p><b>Section:</b> 30.7.9 <a href="https://wg21.link/time.clock.local">[time.clock.local]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
67+
<b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2025-05-16 <b>Last modified:</b> 2025-05-16</p>
68+
<p><b>Priority: </b>Not Prioritized
69+
</p>
70+
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
71+
<p><b>Discussion:</b></p>
72+
<p>
73+
Stream insertion for <code class='backtick'>chrono::local_time</code> is defined in terms of conversion to
74+
<code class='backtick'>chrono::sys_time</code>, but not all <code class='backtick'>chrono::sys_time</code> specializations
75+
can be inserted into an ostream, because one of the overloads is
76+
constrained and the other requires convertibility to <code class='backtick'>chrono::sys_days</code>
77+
(see 30.7.2.3 <a href="https://wg21.link/time.clock.system.nonmembers">[time.clock.system.nonmembers]</a>).
78+
</p>
79+
<p>
80+
This means the following code fails to compile:
81+
<pre><code>
82+
#include &lt;iostream&gt;
83+
#include &lt;chrono&gt;
84+
85+
template&lt;typename T&gt;
86+
concept ostream_insertable = requires (std::ostream&amp; o, const T&amp; t) { o &lt;&lt; t; };
87+
88+
using D = std::chrono::duration&lt;double&gt;;
89+
90+
int main() {
91+
if constexpr (ostream_insertable&lt;std::chrono::sys_time&lt;D&gt;&gt;)
92+
std::cout &lt;&lt; std::chrono::sys_time&lt;D&gt;{};
93+
if constexpr (ostream_insertable&lt;std::chrono::local_time&lt;D&gt;&gt;)
94+
std::cout &lt;&lt; std::chrono::local_time&lt;D&gt;{}; // <b>FAIL</b>
95+
}
96+
</code></pre>
97+
The first condition is false, because there's no overload that's suitable.
98+
The second is true, because the <code>operator&lt;&lt;</code> overload for
99+
<code class='backtick'>chrono::local_time</code> isn't constrained and so insertion appears to be valid.
100+
But actually trying to use it is ill-formed, because it tries to convert the
101+
<code>local_time&lt;D&gt;</code> to a <code>sys_time&lt;D&gt;</code>
102+
and then insert that, which isn't valid.
103+
</p>
104+
105+
106+
<p id="res-4257"><b>Proposed resolution:</b></p>
107+
<p>
108+
This wording is relative to <a href="https://wg21.link/N5008">N5008</a>.
109+
</p>
110+
111+
<ol>
112+
<li><p>Modify 30.7.9 <a href="https://wg21.link/time.clock.local">[time.clock.local]</a> as indicated:</p>
113+
114+
<blockquote>
115+
<pre><code>
116+
template&lt;class charT, class traits, class Duration&gt;
117+
basic_ostream&lt;charT, traits&gt;&amp;
118+
operator&lt;&lt;(basic_ostream&lt;charT, traits&gt;&amp; os, const local_time&lt;Duration&gt;&amp; lt);
119+
</code></pre>
120+
<p><ins>-?- <i>Constraints</i>:
121+
<code>os &lt;&lt; sys_time&lt;Duration&gt;{lt.time_since_epoch()}</code>
122+
is a valid expression.</ins>
123+
</p>
124+
<p>-2- <i>Effects</i>:
125+
<pre><code> os &lt;&lt; sys_time&lt;Duration&gt;{lt.time_since_epoch()};
126+
</code></pre>
127+
</p>
128+
<p>-3- <i>Returns</i>: <code class='backtick'>os</code>.</p>
129+
</blockquote>
130+
</li>
131+
</ol>
132+
133+
134+
135+
136+
137+
138+
</body>
139+
</html>

0 commit comments

Comments
 (0)