[libcxx-commits] [libcxx] f02c9e6 - [libc++] Addresses LWG3755.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 31 11:08:13 PST 2023


Author: Mark de Wever
Date: 2023-01-31T20:08:07+01:00
New Revision: f02c9e6f26fcda80b93e6a68100268a005b5c2c5

URL: https://github.com/llvm/llvm-project/commit/f02c9e6f26fcda80b93e6a68100268a005b5c2c5
DIFF: https://github.com/llvm/llvm-project/commit/f02c9e6f26fcda80b93e6a68100268a005b5c2c5.diff

LOG: [libc++] Addresses LWG3755.

  LWG3755 tuple-for-each can call user-defined operator,

Reviewed By: #libc, ldionne, philnik

Differential Revision: https://reviews.llvm.org/D142909

Added: 
    libcxx/test/libcxx/ranges/range.adaptors/range.adaptor.tuple/tuple-for-each.pass.cpp

Modified: 
    libcxx/docs/Status/Cxx2bIssues.csv
    libcxx/include/__ranges/zip_view.h

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/Status/Cxx2bIssues.csv b/libcxx/docs/Status/Cxx2bIssues.csv
index b286ad3d6b35..98f6eec40f80 100644
--- a/libcxx/docs/Status/Cxx2bIssues.csv
+++ b/libcxx/docs/Status/Cxx2bIssues.csv
@@ -212,7 +212,7 @@
 "`3751 <https://wg21.link/LWG3751>`__","Missing feature macro for ``flat_set``", "November 2022","","","|flat_containers|"
 "`3753 <https://wg21.link/LWG3753>`__","Clarify entity vs. freestanding entity", "November 2022","","",""
 "`3754 <https://wg21.link/LWG3754>`__","Class template expected synopsis contains declarations that do not match the detailed description", "November 2022","|Nothing to do|","",""
-"`3755 <https://wg21.link/LWG3755>`__","``tuple-for-each`` can call ``user-defined`` ``operator,``", "November 2022","","",""
+"`3755 <https://wg21.link/LWG3755>`__","``tuple-for-each`` can call ``user-defined`` ``operator,``", "November 2022","|Complete|","17.0",""
 "`3757 <https://wg21.link/LWG3757>`__","What's the effect of ``std::forward_like<void>(x)``?", "November 2022","","",""
 "`3759 <https://wg21.link/LWG3759>`__","``ranges::rotate_copy`` should use ``std::move``", "November 2022","","","|ranges|"
 "`3760 <https://wg21.link/LWG3760>`__","``cartesian_product_view::iterator``'s ``parent_`` is never valid", "November 2022","","","|ranges|"

diff  --git a/libcxx/include/__ranges/zip_view.h b/libcxx/include/__ranges/zip_view.h
index 5624726e13ee..2f3f69d69b4a 100644
--- a/libcxx/include/__ranges/zip_view.h
+++ b/libcxx/include/__ranges/zip_view.h
@@ -77,7 +77,9 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto __tuple_transform(_Fun&& __f, _Tuple&& __tu
 template <class _Fun, class _Tuple>
 _LIBCPP_HIDE_FROM_ABI constexpr void __tuple_for_each(_Fun&& __f, _Tuple&& __tuple) {
   std::apply(
-      [&]<class... _Types>(_Types&&... __elements) { (std::invoke(__f, std::forward<_Types>(__elements)), ...); },
+      [&]<class... _Types>(_Types&&... __elements) {
+        (static_cast<void>(std::invoke(__f, std::forward<_Types>(__elements))), ...);
+      },
       std::forward<_Tuple>(__tuple));
 }
 

diff  --git a/libcxx/test/libcxx/ranges/range.adaptors/range.adaptor.tuple/tuple-for-each.pass.cpp b/libcxx/test/libcxx/ranges/range.adaptors/range.adaptor.tuple/tuple-for-each.pass.cpp
new file mode 100644
index 000000000000..11176c757efa
--- /dev/null
+++ b/libcxx/test/libcxx/ranges/range.adaptors/range.adaptor.tuple/tuple-for-each.pass.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// <ranges>
+
+// template<class F, class Tuple>
+// constexpr void tuple-for-each(F&& f, Tuple&& t) { // exposition only
+
+// LWG3755 tuple-for-each can call user-defined operator,
+
+#include <ranges>
+#include <tuple>
+#include <cstdlib>
+
+struct Evil {
+  void operator,(Evil) { std::abort(); }
+};
+
+int main(int, char**) {
+  std::tuple<int, int> t;
+  std::ranges::__tuple_for_each([](int) { return Evil{}; }, t);
+
+  return 0;
+}


        


More information about the libcxx-commits mailing list