Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] P2602R2 Poison Pills are Too Toxic #74534

Merged
merged 23 commits into from
Mar 16, 2024

Conversation

JMazurkiewicz
Copy link
Contributor

@JMazurkiewicz JMazurkiewicz commented Dec 5, 2023

Implements P2602R2 Poison Pills are Too Toxic as a DR in C++20 mode.

@JMazurkiewicz JMazurkiewicz requested a review from a team as a code owner December 5, 2023 23:00
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Dec 5, 2023
@llvmbot
Copy link

llvmbot commented Dec 5, 2023

@llvm/pr-subscribers-libcxx

Author: Jakub Mazurkiewicz (JMazurkiewicz)

Changes

This PR contains P2602R2 implemented as a DR in C++20 mode.


Patch is 43.74 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/74534.diff

30 Files Affected:

  • (modified) libcxx/docs/FeatureTestMacroTable.rst (+1-1)
  • (modified) libcxx/docs/Status/Cxx23Papers.csv (+1-1)
  • (modified) libcxx/include/__compare/partial_order.h (+2)
  • (modified) libcxx/include/__compare/strong_order.h (+2)
  • (modified) libcxx/include/__compare/weak_order.h (+2)
  • (modified) libcxx/include/__iterator/iter_move.h (+1-1)
  • (modified) libcxx/include/__ranges/access.h (+2-4)
  • (modified) libcxx/include/__ranges/rbegin.h (+1-2)
  • (modified) libcxx/include/__ranges/rend.h (+1-2)
  • (modified) libcxx/include/__ranges/size.h (+1-2)
  • (modified) libcxx/include/version (+2-2)
  • (modified) libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp (+11)
  • (modified) libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.swap/iter_swap.pass.cpp (+6)
  • (added) libcxx/test/std/language.support/cmp/cmp.alg/ordinary_unqualified_lookup_helpers.h (+33)
  • (modified) libcxx/test/std/language.support/cmp/cmp.alg/partial_order.pass.cpp (+9)
  • (modified) libcxx/test/std/language.support/cmp/cmp.alg/strong_order.pass.cpp (+9)
  • (modified) libcxx/test/std/language.support/cmp/cmp.alg/weak_order.pass.cpp (+9)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/algorithm.version.compile.pass.cpp (+7-7)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/functional.version.compile.pass.cpp (+7-7)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/iterator.version.compile.pass.cpp (+7-7)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/memory.version.compile.pass.cpp (+7-7)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/ranges.version.compile.pass.cpp (+7-7)
  • (modified) libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp (+7-7)
  • (modified) libcxx/test/std/ranges/range.access/begin.pass.cpp (+13-5)
  • (modified) libcxx/test/std/ranges/range.access/end.pass.cpp (+14-6)
  • (added) libcxx/test/std/ranges/range.access/ordinary_unqualified_lookup_helpers.h (+25)
  • (modified) libcxx/test/std/ranges/range.access/rbegin.pass.cpp (+13-5)
  • (modified) libcxx/test/std/ranges/range.access/rend.pass.cpp (+14-6)
  • (modified) libcxx/test/std/ranges/range.access/size.pass.cpp (+8-1)
  • (modified) libcxx/utils/generate_feature_test_macro_components.py (+1-1)
diff --git a/libcxx/docs/FeatureTestMacroTable.rst b/libcxx/docs/FeatureTestMacroTable.rst
index d09f65b7cadc0..f4788aa574788 100644
--- a/libcxx/docs/FeatureTestMacroTable.rst
+++ b/libcxx/docs/FeatureTestMacroTable.rst
@@ -266,7 +266,7 @@ Status
     --------------------------------------------------- -----------------
     ``__cpp_lib_polymorphic_allocator``                 ``201902L``
     --------------------------------------------------- -----------------
-    ``__cpp_lib_ranges``                                ``202207L``
+    ``__cpp_lib_ranges``                                ``202211L``
     --------------------------------------------------- -----------------
     ``__cpp_lib_remove_cvref``                          ``201711L``
     --------------------------------------------------- -----------------
diff --git a/libcxx/docs/Status/Cxx23Papers.csv b/libcxx/docs/Status/Cxx23Papers.csv
index e03cbff2a08bb..7dc6f36ba1e63 100644
--- a/libcxx/docs/Status/Cxx23Papers.csv
+++ b/libcxx/docs/Status/Cxx23Papers.csv
@@ -100,7 +100,7 @@
 "`P2396R1 <https://wg21.link/P2396R1>`__","LWG", "Concurrency TS 2 fixes ", "November 2022","","","|concurrency TS|"
 "`P2505R5 <https://wg21.link/P2505R5>`__","LWG", "Monadic Functions for ``std::expected``", "November 2022","|Complete|","17.0",""
 "`P2539R4 <https://wg21.link/P2539R4>`__","LWG", "Should the output of ``std::print`` to a terminal be synchronized with the underlying stream?", "November 2022","|In Progress|","","|format|"
-"`P2602R2 <https://wg21.link/P2602R2>`__","LWG", "Poison Pills are Too Toxic", "November 2022","","","|ranges|"
+"`P2602R2 <https://wg21.link/P2602R2>`__","LWG", "Poison Pills are Too Toxic", "November 2022","|Complete|","18.0","|ranges|"
 "`P2708R1 <https://wg21.link/P2708R1>`__","LWG", "No Further Fundamentals TSes", "November 2022","|Nothing to do|","",""
 "","","","","","",""
 "`P0290R4 <https://wg21.link/P0290R4>`__","LWG", "``apply()`` for ``synchronized_value<T>``","February 2023","","","|concurrency TS|"
diff --git a/libcxx/include/__compare/partial_order.h b/libcxx/include/__compare/partial_order.h
index 36a11dfaa2881..b422bdd4ef841 100644
--- a/libcxx/include/__compare/partial_order.h
+++ b/libcxx/include/__compare/partial_order.h
@@ -28,6 +28,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // [cmp.alg]
 namespace __partial_order {
+    void partial_order() = delete;
+
     struct __fn {
     // NOLINTBEGIN(libcpp-robust-against-adl) partial_order should use ADL, but only here
         template<class _Tp, class _Up>
diff --git a/libcxx/include/__compare/strong_order.h b/libcxx/include/__compare/strong_order.h
index cbfcf7316de9e..ba59cb51b86d9 100644
--- a/libcxx/include/__compare/strong_order.h
+++ b/libcxx/include/__compare/strong_order.h
@@ -34,6 +34,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // [cmp.alg]
 namespace __strong_order {
+    void strong_order() = delete;
+
     struct __fn {
     // NOLINTBEGIN(libcpp-robust-against-adl) strong_order should use ADL, but only here
         template<class _Tp, class _Up>
diff --git a/libcxx/include/__compare/weak_order.h b/libcxx/include/__compare/weak_order.h
index e6a42ac4c9235..8d7f939092303 100644
--- a/libcxx/include/__compare/weak_order.h
+++ b/libcxx/include/__compare/weak_order.h
@@ -28,6 +28,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // [cmp.alg]
 namespace __weak_order {
+    void weak_order() = delete;
+
     struct __fn {
     // NOLINTBEGIN(libcpp-robust-against-adl) weak_order should use ADL, but only here
         template<class _Tp, class _Up>
diff --git a/libcxx/include/__iterator/iter_move.h b/libcxx/include/__iterator/iter_move.h
index d9ff90bf65456..79dcac8f50b9f 100644
--- a/libcxx/include/__iterator/iter_move.h
+++ b/libcxx/include/__iterator/iter_move.h
@@ -35,7 +35,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 namespace ranges {
 namespace __iter_move {
 
-void iter_move();
+void iter_move() = delete;
 
 template <class _Tp>
 concept __unqualified_iter_move =
diff --git a/libcxx/include/__ranges/access.h b/libcxx/include/__ranges/access.h
index 502bd5e951c4a..01bf8cc2f544f 100644
--- a/libcxx/include/__ranges/access.h
+++ b/libcxx/include/__ranges/access.h
@@ -49,8 +49,7 @@ namespace __begin {
       { _LIBCPP_AUTO_CAST(__t.begin()) } -> input_or_output_iterator;
     };
 
-  void begin(auto&) = delete;
-  void begin(const auto&) = delete;
+  void begin() = delete;
 
   template <class _Tp>
   concept __unqualified_begin =
@@ -121,8 +120,7 @@ namespace __end {
       { _LIBCPP_AUTO_CAST(__t.end()) } -> sentinel_for<iterator_t<_Tp>>;
     };
 
-  void end(auto&) = delete;
-  void end(const auto&) = delete;
+  void end() = delete;
 
   template <class _Tp>
   concept __unqualified_end =
diff --git a/libcxx/include/__ranges/rbegin.h b/libcxx/include/__ranges/rbegin.h
index 1ceb1116d695f..8fd17a3c016a2 100644
--- a/libcxx/include/__ranges/rbegin.h
+++ b/libcxx/include/__ranges/rbegin.h
@@ -43,8 +43,7 @@ concept __member_rbegin =
     { _LIBCPP_AUTO_CAST(__t.rbegin()) } -> input_or_output_iterator;
   };
 
-void rbegin(auto&) = delete;
-void rbegin(const auto&) = delete;
+void rbegin() = delete;
 
 template <class _Tp>
 concept __unqualified_rbegin =
diff --git a/libcxx/include/__ranges/rend.h b/libcxx/include/__ranges/rend.h
index 7ee574ccfa674..1f482963ac749 100644
--- a/libcxx/include/__ranges/rend.h
+++ b/libcxx/include/__ranges/rend.h
@@ -45,8 +45,7 @@ concept __member_rend =
     { _LIBCPP_AUTO_CAST(__t.rend()) } -> sentinel_for<decltype(ranges::rbegin(__t))>;
   };
 
-void rend(auto&) = delete;
-void rend(const auto&) = delete;
+void rend() = delete;
 
 template <class _Tp>
 concept __unqualified_rend =
diff --git a/libcxx/include/__ranges/size.h b/libcxx/include/__ranges/size.h
index f22dd1ff7b79f..0ed939e0bd4f9 100644
--- a/libcxx/include/__ranges/size.h
+++ b/libcxx/include/__ranges/size.h
@@ -41,8 +41,7 @@ namespace ranges {
 
 namespace ranges {
 namespace __size {
-void size(auto&) = delete;
-void size(const auto&) = delete;
+void size() = delete;
 
 template <class _Tp>
 concept __size_enabled = !disable_sized_range<remove_cvref_t<_Tp>>;
diff --git a/libcxx/include/version b/libcxx/include/version
index e84790b888d33..71937c3a3d1c2 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -164,7 +164,7 @@ __cpp_lib_parallel_algorithm                            201603L <algorithm> <num
 __cpp_lib_polymorphic_allocator                         201902L <memory_resource>
 __cpp_lib_print                                         202207L <ostream> <print>
 __cpp_lib_quoted_string_io                              201304L <iomanip>
-__cpp_lib_ranges                                        202207L <algorithm> <functional> <iterator>
+__cpp_lib_ranges                                        202211L <algorithm> <functional> <iterator>
                                                                 <memory> <ranges>
 __cpp_lib_ranges_as_const                               202207L <ranges>
 __cpp_lib_ranges_as_rvalue                              202207L <ranges>
@@ -405,7 +405,7 @@ __cpp_lib_within_lifetime                               202306L <type_traits>
 # if _LIBCPP_AVAILABILITY_HAS_PMR
 #   define __cpp_lib_polymorphic_allocator              201902L
 # endif
-# define __cpp_lib_ranges                               202207L
+# define __cpp_lib_ranges                               202211L
 # define __cpp_lib_remove_cvref                         201711L
 # if !defined(_LIBCPP_HAS_NO_THREADS) && _LIBCPP_AVAILABILITY_HAS_SYNC
 #   define __cpp_lib_semaphore                          201907L
diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp
index 566638263e887..8cd515d8e7fb4 100644
--- a/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.move/iter_move.pass.cpp
@@ -11,6 +11,14 @@
 // template<class I>
 // unspecified iter_move;
 
+// Note: this struct is intentionally defined before any other header is included.
+// Custom `iter_move` must be visible to `std::ranges::iter_move` CPO from `<iterator>` header.
+namespace nest {
+struct StructWithGlobalIterMove {};
+} // namespace nest
+
+int&& iter_move(nest::StructWithGlobalIterMove);
+
 #include <algorithm>
 #include <array>
 #include <cassert>
@@ -186,6 +194,9 @@ template<class T> struct Holder { T t; };
 static_assert(std::is_invocable_v<IterMoveT, Holder<Incomplete>**>);
 static_assert(std::is_invocable_v<IterMoveT, Holder<Incomplete>**&>);
 
+// Ordinary unqualified lookup should not be performed.
+static_assert(!std::is_invocable_v<IterMoveT, nest::StructWithGlobalIterMove&>);
+
 int main(int, char**)
 {
   test();
diff --git a/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.swap/iter_swap.pass.cpp b/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.swap/iter_swap.pass.cpp
index dd78707f25409..692ddef195d2c 100644
--- a/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.swap/iter_swap.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.requirements/iterator.cust/iterator.cust.swap/iter_swap.pass.cpp
@@ -47,6 +47,12 @@ static_assert( std::is_invocable_v<IterSwapT&&, HasIterSwap&, HasIterSwap&>);
 static_assert( std::is_invocable_v<IterSwapT&&, HasIterSwap&, int&>);
 static_assert(!std::is_invocable_v<IterSwapT&&, int&, HasIterSwap&>);
 
+struct NotMoreSpecializedIterSwap {
+  friend void iter_swap(auto&, auto&);
+};
+
+static_assert(!std::is_invocable_v<IterSwapT, NotMoreSpecializedIterSwap&, NotMoreSpecializedIterSwap&>);
+
 struct NodiscardIterSwap {
   [[nodiscard]] friend int iter_swap(NodiscardIterSwap&, NodiscardIterSwap&) { return 0; }
 };
diff --git a/libcxx/test/std/language.support/cmp/cmp.alg/ordinary_unqualified_lookup_helpers.h b/libcxx/test/std/language.support/cmp/cmp.alg/ordinary_unqualified_lookup_helpers.h
new file mode 100644
index 0000000000000..4cbe163c312f4
--- /dev/null
+++ b/libcxx/test/std/language.support/cmp/cmp.alg/ordinary_unqualified_lookup_helpers.h
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEST_STD_LANGUAGE_SUPPORT_CMP_CMP_ALG_ORDINARY_UNQUALIFIED_LOOKUP_HELPERS_H
+#define TEST_STD_LANGUAGE_SUPPORT_CMP_CMP_ALG_ORDINARY_UNQUALIFIED_LOOKUP_HELPERS_H
+
+// Note: this header should be included before any other header.
+// Comparison functions defined here must be visible to CPOs from `<compare>` header.
+
+namespace nest {
+struct StructWithGlobalCmpFunctions {};
+} // namespace nest
+
+struct ConvertibleToComparisonType;
+
+ConvertibleToComparisonType strong_order(nest::StructWithGlobalCmpFunctions, nest::StructWithGlobalCmpFunctions);
+ConvertibleToComparisonType weak_order(nest::StructWithGlobalCmpFunctions, nest::StructWithGlobalCmpFunctions);
+ConvertibleToComparisonType partial_order(nest::StructWithGlobalCmpFunctions, nest::StructWithGlobalCmpFunctions);
+
+#include <compare> // Intentionally included here, so we can define `ConvertibleToComparisonType` later.
+
+struct ConvertibleToComparisonType {
+  operator std::strong_ordering() const;
+  operator std::weak_ordering() const;
+  operator std::partial_ordering() const;
+};
+
+#endif // TEST_STD_LANGUAGE_SUPPORT_CMP_CMP_ALG_ORDINARY_UNQUALIFIED_LOOKUP_HELPERS_H
diff --git a/libcxx/test/std/language.support/cmp/cmp.alg/partial_order.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.alg/partial_order.pass.cpp
index bd313889b1a4e..d6376f0a5cb2a 100644
--- a/libcxx/test/std/language.support/cmp/cmp.alg/partial_order.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.alg/partial_order.pass.cpp
@@ -12,6 +12,10 @@
 
 // template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
 
+// Note: this header is intentionally included before any other header.
+// Comparison functions defined there must be visible to CPOs from `<compare>` header.
+#include "ordinary_unqualified_lookup_helpers.h"
+
 #include <compare>
 
 #include <cassert>
@@ -240,6 +244,11 @@ constexpr bool test_1_4()
     return true;
 }
 
+// Ordinary unqualified lookup should not be performed.
+static_assert(!std::is_invocable_v<decltype(std::partial_order),
+                                   nest::StructWithGlobalCmpFunctions,
+                                   nest::StructWithGlobalCmpFunctions>);
+
 int main(int, char**)
 {
     test_1_1();
diff --git a/libcxx/test/std/language.support/cmp/cmp.alg/strong_order.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.alg/strong_order.pass.cpp
index ac6b6879f7730..5c26a0be23f0a 100644
--- a/libcxx/test/std/language.support/cmp/cmp.alg/strong_order.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.alg/strong_order.pass.cpp
@@ -12,6 +12,10 @@
 
 // template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
 
+// Note: this header is intentionally included before any other header.
+// Comparison functions defined there must be visible to CPOs from `<compare>` header.
+#include "ordinary_unqualified_lookup_helpers.h"
+
 #include <compare>
 
 #include <cassert>
@@ -448,6 +452,11 @@ constexpr bool test_1_4()
     return true;
 }
 
+// Ordinary unqualified lookup should not be performed.
+static_assert(!std::is_invocable_v<decltype(std::strong_order),
+                                   nest::StructWithGlobalCmpFunctions,
+                                   nest::StructWithGlobalCmpFunctions>);
+
 int main(int, char**)
 {
     test_1_1();
diff --git a/libcxx/test/std/language.support/cmp/cmp.alg/weak_order.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.alg/weak_order.pass.cpp
index 09d720196e0b2..0dc79acc99ed9 100644
--- a/libcxx/test/std/language.support/cmp/cmp.alg/weak_order.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.alg/weak_order.pass.cpp
@@ -12,6 +12,10 @@
 
 // template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
 
+// Note: this header is intentionally included before any other header.
+// Comparison functions defined there must be visible to CPOs from `<compare>` header.
+#include "ordinary_unqualified_lookup_helpers.h"
+
 #include <compare>
 
 #include <cassert>
@@ -493,6 +497,11 @@ constexpr bool test_1_5()
     return true;
 }
 
+// Ordinary unqualified lookup should not be performed.
+static_assert(!std::is_invocable_v<decltype(std::weak_order),
+                                   nest::StructWithGlobalCmpFunctions,
+                                   nest::StructWithGlobalCmpFunctions>);
+
 int main(int, char**)
 {
     test_1_1();
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/algorithm.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/algorithm.version.compile.pass.cpp
index ec6503ec23755..918c6d35f730d 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/algorithm.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/algorithm.version.compile.pass.cpp
@@ -20,7 +20,7 @@
     __cpp_lib_constexpr_algorithms           201806L [C++20]
     __cpp_lib_freestanding_algorithm         202311L [C++26]
     __cpp_lib_parallel_algorithm             201603L [C++17]
-    __cpp_lib_ranges                         202207L [C++20]
+    __cpp_lib_ranges                         202211L [C++20]
     __cpp_lib_ranges_starts_ends_with        202106L [C++23]
     __cpp_lib_robust_nonmodifying_seq_ops    201304L [C++14]
     __cpp_lib_sample                         201603L [C++17]
@@ -201,8 +201,8 @@
 # ifndef __cpp_lib_ranges
 #   error "__cpp_lib_ranges should be defined in c++20"
 # endif
-# if __cpp_lib_ranges != 202207L
-#   error "__cpp_lib_ranges should have the value 202207L in c++20"
+# if __cpp_lib_ranges != 202211L
+#   error "__cpp_lib_ranges should have the value 202211L in c++20"
 # endif
 
 # ifdef __cpp_lib_ranges_starts_ends_with
@@ -266,8 +266,8 @@
 # ifndef __cpp_lib_ranges
 #   error "__cpp_lib_ranges should be defined in c++23"
 # endif
-# if __cpp_lib_ranges != 202207L
-#   error "__cpp_lib_ranges should have the value 202207L in c++23"
+# if __cpp_lib_ranges != 202211L
+#   error "__cpp_lib_ranges should have the value 202211L in c++23"
 # endif
 
 # if !defined(_LIBCPP_VERSION)
@@ -349,8 +349,8 @@
 # ifndef __cpp_lib_ranges
 #   error "__cpp_lib_ranges should be defined in c++26"
 # endif
-# if __cpp_lib_ranges != 202207L
-#   error "__cpp_lib_ranges should have the value 202207L in c++26"
+# if __cpp_lib_ranges != 202211L
+#   error "__cpp_lib_ranges should have the value 202211L in c++26"
 # endif
 
 # if !defined(_LIBCPP_VERSION)
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/functional.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/functional.version.compile.pass.cpp
index 72c96c62b64c4..55674d104fab9 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/functional.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/functional.version.compile.pass.cpp
@@ -28,7 +28,7 @@
     __cpp_lib_invoke_r                 202106L [C++23]
     __cpp_lib_move_only_function       202110L [C++23]
     __cpp_lib_not_fn                   201603L [C++17]
-    __cpp_lib_ranges                   202207L [C++20]
+    __cpp_lib_ranges                   202211L [C++20]
     __cpp_lib_result_of_sfinae         201210L [C++14]
     __cpp_lib_transparent_operators    201210L [C++14]
                                        201510L [C++17]
@@ -293,8 +293,8 @@
 # ifndef __cpp_lib_ranges
 #   error "__cpp_lib_ranges should be defined in c++20"
 # endif
-# if __cpp_lib_ranges != 202207L
-#   error "__cpp_lib_ranges should have the value 202207L in c++20"
+# if __cpp_lib_ranges != 202211L
+#   error "__cpp_lib_ranges should have the value 202211L in c++20"
 # endif
 
 # ifndef __cpp_lib_result_of_sfinae
@@ -399,8 +399,8 @@
 # ifndef __cpp_lib_ranges
 #   error "__cpp_lib_ranges should be defined in c++23"
 # endif
-# if __cpp_lib_ranges != 202207L
-#   error "__cpp_lib_ranges should have the value 202207L in c++23"
+# if __cpp_lib_ranges != 202211L
+#   error "__cpp_lib_ranges should have the value 202211L in c++23"
 # endif
 
 # ifndef __cpp_lib_result_of_sfinae
@@ -523,8 +523,8 @@
 # ifndef __cpp_lib_ranges
 #   error "__cpp_lib_ranges should be defined in c++26"
 # endif
-# if __cpp_lib_ranges != 202207L
-#   error "__cpp_lib_ranges should have the value 202207L in c++26"
+# if __cpp_lib_ranges != 202211L
+#   error "__cpp_lib_ranges should have the value 202211L in c++26"
 # endif
 
 # ifndef __cpp_lib_result_of_sfinae
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/iterator.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/iterator.version.compile.pass.cpp
index 700907ce9bb07..6c652e694f6dd 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/iterator.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/iterator.version.compile.pass.cpp
@@ -23,7 +23,7 @@
     __cpp_lib_move_iterator_concept         202207L [C++20]
     __cpp_lib_nonmember_container_access    201411L [C++17]
     __cpp_lib_null_iterators                201304L [C++14]
-    __cpp_lib_ranges                        202207L [C++20]
+    __cpp_lib_ranges                        202211L [C++20]
     __cpp_lib_ssize                         201902L [C++20]
 */
 
@@ -197,8 +197,8 @@
 # ifndef __cpp_lib_ranges
 #   error "__cpp_lib_ranges should be defined in c++20"
 # endif
-# if __cpp_lib_ranges != 202207L
-#   error "__cpp_lib_ranges should have the value 202207L in c++20"
+# if __cpp_lib_ranges != 202211L
+#   error "__cpp_lib_ranges should have the value 202211L in c++20"
 # endif
 
 # ifndef __cpp_lib_ssize
@@ -255,8 +255,8 @@
 # ifndef __cpp_lib_ranges
 #   error "__cpp_lib_rang...
[truncated]

Copy link

github-actions bot commented Dec 5, 2023

✅ With the latest revision this PR passed the Python code formatter.

Copy link

github-actions bot commented Dec 5, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@philnik777
Copy link
Contributor

Could you add some reasoning why this should be DRed?

@JMazurkiewicz
Copy link
Contributor Author

JMazurkiewicz commented Dec 6, 2023

Could you add some reasoning why this should be DRed?

MSVC and libstdc++ already implemented this paper as a DR. It mainly fixes this (rather) unexpected behaviour:

// https://godbolt.org/z/9h954faET
#include <ranges>

struct Ints {
    friend int* begin(const Ints&);
    friend int* end(const Ints&);
};

// Good
static_assert(std::ranges::range<const Ints>);

// FAIL! It looks like defect in C++20 ranges design.
static_assert(std::ranges::range<Ints>);

And quote from the paper (end of §4):

[...] the poison pills prevent reasonable code from working and it’s entirely unclear whether they prevent unreasonable code from working.

@cjdb
Copy link
Contributor

cjdb commented Dec 6, 2023

I support applying this to C++20.

@var-const var-const added the ranges Issues related to `<ranges>` label Mar 8, 2024
Copy link
Contributor

@huixie90 huixie90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@huixie90 huixie90 merged commit 12978b3 into llvm:main Mar 16, 2024
52 checks passed
@JMazurkiewicz JMazurkiewicz deleted the libcxx/ranges/poison-pills branch March 18, 2024 08:29
JMazurkiewicz added a commit to JMazurkiewicz/llvm-project that referenced this pull request May 13, 2024
* Some docs should've been updated in llvm#74534, this PR does this.
* llvm#89148 should've bumped `__cpp_lib_ranges` macro to 202211 (value mentioned by "P2602R2 Poison Pills are Too Toxic")
* Drive-by: fix order of notes in `Cxx23.rst`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. ranges Issues related to `<ranges>`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants