Skip to content

Commit 1f48f8f

Browse files
committed
[libc++] Avoid UB in year_month_day_last::day() for incorrect months
This effectively implements the resolution of LWG3231, which mandates that calling year_month_day_last::day() on an invalid year_month_day_last is unspecified behavior. Before this change, it was undefined behavior. Differential Revision: https://reviews.llvm.org/D81477
1 parent 2c8afe1 commit 1f48f8f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libcxx/include/chrono

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,7 @@ chrono::day year_month_day_last::day() const noexcept
24542454
chrono::day(31), chrono::day(31), chrono::day(30),
24552455
chrono::day(31), chrono::day(30), chrono::day(31)
24562456
};
2457-
return month() != February || !__y.is_leap() ?
2457+
return (month() != February || !__y.is_leap()) && month().ok() ?
24582458
__d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
24592459
}
24602460

0 commit comments

Comments
 (0)