[libc++] Remove assertion in year_month_day_last::day()
authorLouis Dionne <ldionne@apple.com>
Tue, 9 Jun 2020 14:35:41 +0000 (10:35 -0400)
committerLouis Dionne <ldionne@apple.com>
Tue, 9 Jun 2020 14:46:13 +0000 (10:46 -0400)
This reverts commit 0c148430cf61, 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

libcxx/include/chrono
libcxx/test/libcxx/algorithms/debug_less.pass.cpp
libcxx/test/std/utilities/time/time.cal/time.cal.operators/year_month_day_last.pass.cpp

index 9913dc1..6e5de39 100644 (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};
 }
index 8a38a80..6dd5695 100644 (file)
 
 // __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())
 
index af99b4e..7648999 100644 (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;
 }