Skip to content

Commit e25a260

Browse files
committed
[libc++] [LWG3321] Mark "year_month_day_last::day() specification does not cover !ok() values" issue as "Nothing to do", but add assertion.
Summary: This LWG issue states that the result of `year_month_day_last::day()` is implementation defined if `ok()` is `false`. However, from user perspective, calling `day()` in this situation will lead to a (possibly difficult to find) crash. Hence, I have added an assertion to warn user at least when assertions are enabled. I am however not aware of the libc++ stand on the desired behaviour. Reviewers: ldionne, mclow.lists, EricWF, #libc Reviewed By: ldionne, #libc Subscribers: christof, dexonsmith, libcxx-commits Tags: #libc Differential Revision: https://reviews.llvm.org/D70346
1 parent 2866c6c commit e25a260

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

libcxx/include/chrono

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ constexpr chrono::year operator ""y(unsigned lo
824824
*/
825825

826826
#include <__config>
827+
#include <__debug>
827828
#include <ctime>
828829
#include <type_traits>
829830
#include <ratio>
@@ -2454,6 +2455,7 @@ chrono::day year_month_day_last::day() const noexcept
24542455
chrono::day(31), chrono::day(31), chrono::day(30),
24552456
chrono::day(31), chrono::day(30), chrono::day(31)
24562457
};
2458+
_LIBCPP_ASSERT(ok(), "year_month_day_last::day(): year_month_day_last is invalid");
24572459
return month() != February || !__y.is_leap() ?
24582460
__d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
24592461
}

libcxx/www/cxx2a_status.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ <h3>Library Working group Issues Status</h3>
439439
<tr><td><a href="https://wg21.link/LWG3209">3209</a></td><td>Expression in <tt>year::ok()</tt> returns clause is ill-formed</td><td>Cologne</td><td>Complete</td></tr>
440440

441441
<tr><td></td><td></td><td></td><td></td></tr>
442-
<tr><td><a href="https://wg21.link/LWG3231">3231</a></td><td><tt>year_month_day_last::day</tt> specification does not cover <tt>!ok()</tt> values</td><td>Belfast</td><td></td></tr>
442+
<tr><td><a href="https://wg21.link/LWG3231">3231</a></td><td><tt>year_month_day_last::day</tt> specification does not cover <tt>!ok()</tt> values</td><td>Belfast</td><td><i>Nothing to do</i></td></tr>
443443
<tr><td><a href="https://wg21.link/LWG3225">3225</a></td><td><tt>zoned_time</tt> converting constructor shall not be <tt>noexcept</tt></td><td>Belfast</td><td></td></tr>
444444
<tr><td><a href="https://wg21.link/LWG3190">3190</a></td><td><tt>std::allocator::allocate</tt> sometimes returns too little storage</td><td>Belfast</td><td></td></tr>
445445
<tr><td><a href="https://wg21.link/LWG3218">3218</a></td><td>Modifier for <tt>%d</tt> parse flag does not match POSIX and <tt>format</tt> specification</td><td>Belfast</td><td></td></tr>

0 commit comments

Comments
 (0)