forked from OSchip/llvm-project
[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
This commit is contained in:
parent
2c8afe1298
commit
1f48f8f6e2
|
@ -2454,7 +2454,7 @@ chrono::day year_month_day_last::day() const noexcept
|
|||
chrono::day(31), chrono::day(31), chrono::day(30),
|
||||
chrono::day(31), chrono::day(30), chrono::day(31)
|
||||
};
|
||||
return month() != February || !__y.is_leap() ?
|
||||
return (month() != February || !__y.is_leap()) && month().ok() ?
|
||||
__d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue