<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - year_month_day_last::day() has undefined behavior and should not"
href="https://bugs.llvm.org/show_bug.cgi?id=47125">47125</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>year_month_day_last::day() has undefined behavior and should not
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>howard.hinnant@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>Convenience link: <a href="http://eel.is/c++draft/time.cal.ymdlast.members#15">http://eel.is/c++draft/time.cal.ymdlast.members#15</a>
Example program:
#include <chrono>
int
main()
{
using namespace std::chrono;
auto constexpr ymdl = 2021y/13/last;
auto constexpr d = ymdl.day();
}
Expected result: To compile.
Actual result:
Jade-2:~/Development/cljunk> clang++ -std=c++2a test.cpp -O3
-I../libcxx/include -nostdinc++
test.cpp:8:20: error: constexpr variable 'd' must be initialized by a constant
expression
auto constexpr d = ymdl.day();
^ ~~~~~~~~~~
../libcxx/include/chrono:2457:9: note: read of dereferenced one-past-the-end
pointer is not allowed in a constant expression
__d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
^
../libcxx/include/chrono:2457:9: note: in call to 'day(__d[12])'
test.cpp:8:29: note: in call to '&ymdl->day()'
auto constexpr d = ymdl.day();
^
1 error generated.
----
Cause of error: The year_month_day_last contains a month that is out of range
of the internal array that is indexed by month. This is not a user error.
This should compile and return an unspecified day.
I see two plausible directions for a fix:
1. Maximal performance: If !this->ok(), take the branch that does not index
and return day{29}.
2. Maximal debugability: If !this->ok() return a day such that !d.ok().
Maybe day{0} or day{32}.
The example implementation at <a href="https://github.com/HowardHinnant/date">https://github.com/HowardHinnant/date</a> chose (1).
But I think either of these choices are reasonable. Field experience with the
example implementation has not provided a definitely preferred answer.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>