[libc++] Remove assertion in year_month_day_last::day()

This reverts commit 0c148430cf, which added an assertion in day().
The Standard doesn't allow day() to crash -- instead it says that the
result is unspecified.

Differential Revision: https://reviews.llvm.org/D70346
This commit is contained in:
Louis Dionne 2020-06-09 10:35:41 -04:00
parent 702cf93356
commit cb347a1106
3 changed files with 10 additions and 8 deletions

View File

@ -824,7 +824,6 @@ constexpr chrono::year operator ""y(unsigned lo
*/
#include <__config>
#include <__debug>
#include <ctime>
#include <type_traits>
#include <ratio>
@ -2455,7 +2454,6 @@ 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)
};
_LIBCPP_ASSERT(ok(), "year_month_day_last::day(): year_month_day_last is invalid");
return month() != February || !__y.is_leap() ?
__d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
}

View File

@ -14,13 +14,8 @@
// __debug_less checks that a comparator actually provides a strict-weak ordering.
#include <chrono> // Include before defining _LIBCPP_ASSERT: cannot throw in a function marked noexcept.
struct DebugException {};
#ifdef _LIBCPP_ASSERT
#undef _LIBCPP_ASSERT
#endif
#define _LIBCPP_DEBUG 0
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : throw ::DebugException())

View File

@ -40,6 +40,7 @@
int main(int, char**)
{
using day = std::chrono::day;
using month = std::chrono::month;
using year_month = std::chrono::year_month;
using year = std::chrono::year;
@ -122,5 +123,13 @@ int main(int, char**)
}
}
return 0;
// the result of year_month_day_last::day() is unspecified when !ok(),
// but it shouldn't crash.
{
year_month_day_last ymdl = year{2020}/month{13}/last;
assert(!ymdl.ok());
day d = ymdl.day(); (void)d; // doesn't crash
}
return 0;
}