[libcxx-commits] [PATCH] D115658: [libc++] Fix the noexceptness of __decay_copy.

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 13 12:02:09 PST 2021


Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, zoecarver, libc++.
Quuxplusone added a project: libc++.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added 1 blocking reviewer(s): libc++.

When `a` was an array type, `__decay_copy(a)` was incorrectly marking itself noexcept(false), because it is false that `int[10]` is nothrow convertible to `int[10]` (in fact it is not convertible at all).

We have no tests explicitly for `__decay_copy`, but the new ranges::begin and ranges::end tests fail before this patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115658

Files:
  libcxx/include/__utility/decay_copy.h
  libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp
  libcxx/test/std/ranges/range.access/range.access.end/end.pass.cpp


Index: libcxx/test/std/ranges/range.access/range.access.end/end.pass.cpp
===================================================================
--- libcxx/test/std/ranges/range.access/range.access.end/end.pass.cpp
+++ libcxx/test/std/ranges/range.access/range.access.end/end.pass.cpp
@@ -298,6 +298,13 @@
 ASSERT_NOT_NOEXCEPT(std::ranges::end(std::declval<NoThrowADLEnd<ThrowingIterator<int>>&>()));
 ASSERT_NOT_NOEXCEPT(std::ranges::cend(std::declval<NoThrowADLEnd<ThrowingIterator<int>>&>()));
 
+struct BeginReturnsArrayRef {
+    auto begin() const noexcept -> int(&)[10];
+    auto end() const noexcept -> int(&)[10];
+} brar;
+static_assert(noexcept(std::ranges::end(brar)));
+static_assert(noexcept(std::ranges::cend(brar)));
+
 
 int main(int, char**) {
   testArray();
Index: libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp
===================================================================
--- libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp
+++ libcxx/test/std/ranges/range.access/range.access.begin/begin.pass.cpp
@@ -264,6 +264,13 @@
 ASSERT_NOT_NOEXCEPT(std::ranges::begin(std::declval<NoThrowADLBegin<ThrowingIterator<int>>&>()));
 ASSERT_NOT_NOEXCEPT(std::ranges::cbegin(std::declval<NoThrowADLBegin<ThrowingIterator<int>>&>()));
 
+struct BeginReturnsArrayRef {
+    auto begin() const noexcept -> int(&)[10];
+    auto end() const noexcept -> int(&)[10];
+} brar;
+static_assert(noexcept(std::ranges::begin(brar)));
+static_assert(noexcept(std::ranges::cbegin(brar)));
+
 
 int main(int, char**) {
   testArray();
Index: libcxx/include/__utility/decay_copy.h
===================================================================
--- libcxx/include/__utility/decay_copy.h
+++ libcxx/include/__utility/decay_copy.h
@@ -24,7 +24,7 @@
 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
 typename decay<_Tp>::type __decay_copy(_Tp&& __t)
 #if _LIBCPP_STD_VER > 17
-    noexcept(is_nothrow_convertible_v<_Tp, remove_reference_t<_Tp>>)
+    noexcept(is_nothrow_convertible_v<_Tp, decay_t<_Tp>>)
 #endif
 {
   return _VSTD::forward<_Tp>(__t);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115658.393991.patch
Type: text/x-patch
Size: 2083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211213/ae452078/attachment.bin>


More information about the libcxx-commits mailing list