[libcxx-commits] [PATCH] D70346: [libc++] [LWG3321] Mark "year_month_day_last::day() specification does not cover !ok() values" issue as "Nothing to do", but add assertion.

Marek Kurdej via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 15 05:53:20 PDT 2020


curdeius updated this revision to Diff 264209.
curdeius added a comment.

- Define _NOEXCEPT to nothing for debug_less tests to avoid throwing in noexcept function.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70346/new/

https://reviews.llvm.org/D70346

Files:
  libcxx/include/__config
  libcxx/include/chrono
  libcxx/test/libcxx/algorithms/debug_less.pass.cpp
  libcxx/www/cxx2a_status.html


Index: libcxx/www/cxx2a_status.html
===================================================================
--- libcxx/www/cxx2a_status.html
+++ libcxx/www/cxx2a_status.html
@@ -439,7 +439,7 @@
 	<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>
 
 	<tr><td></td><td></td><td></td><td></td></tr>
-	<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>
+	<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>
 	<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>
 	<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>
 	<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>
Index: libcxx/test/libcxx/algorithms/debug_less.pass.cpp
===================================================================
--- libcxx/test/libcxx/algorithms/debug_less.pass.cpp
+++ libcxx/test/libcxx/algorithms/debug_less.pass.cpp
@@ -14,6 +14,10 @@
 
 // __debug_less checks that a comparator actually provides a strict-weak ordering.
 
+// <algorithm> indirectly includes <chrono> which uses _LIBCPP_ASSERT in a method mareked _NOEXCEPT,
+// but throwing is not allowed in a function marked noexcept, so we define _NOEXCEPT to nothing.
+#define _NOEXCEPT
+
 struct DebugException {};
 
 #define _LIBCPP_DEBUG 0
Index: libcxx/include/chrono
===================================================================
--- libcxx/include/chrono
+++ libcxx/include/chrono
@@ -830,6 +830,8 @@
 #include <limits>
 #include <version>
 
+#include <__debug>
+
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
@@ -2438,14 +2440,14 @@
      inline constexpr chrono::year                     year() const noexcept { return __y; }
      inline constexpr chrono::month                   month() const noexcept { return __mdl.month(); }
      inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
-            constexpr chrono::day                       day() const noexcept;
+            constexpr chrono::day                       day() const _NOEXCEPT;
      inline constexpr operator                     sys_days() const noexcept { return   sys_days{year()/month()/day()}; }
      inline explicit constexpr operator          local_days() const noexcept { return local_days{year()/month()/day()}; }
      inline constexpr bool                               ok() const noexcept { return __y.ok() && __mdl.ok(); }
 };
 
 inline constexpr
-chrono::day year_month_day_last::day() const noexcept
+chrono::day year_month_day_last::day() const _NOEXCEPT
 {
     constexpr chrono::day __d[] =
     {
@@ -2454,6 +2456,7 @@
         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: libcxx/include/__config
===================================================================
--- libcxx/include/__config
+++ libcxx/include/__config
@@ -814,12 +814,20 @@
 #  endif
 #endif
 
-#ifndef _LIBCPP_HAS_NO_NOEXCEPT
-#  define _NOEXCEPT noexcept
-#  define _NOEXCEPT_(x) noexcept(x)
-#else
-#  define _NOEXCEPT throw()
-#  define _NOEXCEPT_(x)
+#ifndef _NOEXCEPT
+#  ifndef _LIBCPP_HAS_NO_NOEXCEPT
+#    define _NOEXCEPT noexcept
+#  else
+#    define _NOEXCEPT throw()
+#  endif
+#endif
+
+#ifndef _NOEXCEPT_
+#  ifndef _LIBCPP_HAS_NO_NOEXCEPT
+#    define _NOEXCEPT_(x) noexcept(x)
+#  else
+#    define _NOEXCEPT_(x)
+#  endif
 #endif
 
 #ifdef _LIBCPP_HAS_NO_UNICODE_CHARS


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70346.264209.patch
Type: text/x-patch
Size: 4326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200515/ab96b122/attachment.bin>


More information about the libcxx-commits mailing list