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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aaccb9e
[libc++] P2602R2 Poison Pills are Too Toxic
JMazurkiewicz Dec 5, 2023
912bc3e
Make 🐍 formatter happy
JMazurkiewicz Dec 5, 2023
079d0e6
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Jan 10, 2024
aabffdd
Formatting
JMazurkiewicz Jan 10, 2024
ccfae95
Formatting (again)
JMazurkiewicz Jan 10, 2024
5f0ad59
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Feb 3, 2024
0b5275c
Code cleanup
JMazurkiewicz Feb 3, 2024
7562e18
Update docs
JMazurkiewicz Feb 5, 2024
caa3aca
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Feb 5, 2024
9429bbf
Fix value of `__cpp_lib_ranges` FTM
JMazurkiewicz Feb 20, 2024
7680d14
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Feb 20, 2024
d908384
Python formatting
JMazurkiewicz Feb 20, 2024
fec6936
Poke CI
JMazurkiewicz Feb 20, 2024
f0c2fe5
Poke CI (again)
JMazurkiewicz Feb 21, 2024
0df473e
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Feb 22, 2024
510a91a
Separate ordinary unqualified lookup tests.
JMazurkiewicz Feb 26, 2024
a1dbe7d
Revert changes to `__cpp_lib_ranges`
JMazurkiewicz Feb 26, 2024
6201b0f
Whitespace cleanup
JMazurkiewicz Feb 26, 2024
58a8e52
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Feb 26, 2024
84ca8f2
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Feb 27, 2024
191568d
Merge `robust_against_ordinary_unqualified_lookup.compile.pass.cpp` t…
JMazurkiewicz Mar 7, 2024
2d54041
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Mar 7, 2024
5328845
Merge branch 'main' into libcxx/ranges/poison-pills
JMazurkiewicz Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcxx/docs/FeatureTestMacroTable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Status
--------------------------------------------------- -----------------
``__cpp_lib_polymorphic_allocator`` ``201902L``
--------------------------------------------------- -----------------
``__cpp_lib_ranges`` ``202207L``
``__cpp_lib_ranges`` ``202211L``
--------------------------------------------------- -----------------
``__cpp_lib_remove_cvref`` ``201711L``
--------------------------------------------------- -----------------
Expand Down
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx23Papers.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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|"
Expand Down
2 changes: 2 additions & 0 deletions libcxx/include/__compare/partial_order.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions libcxx/include/__compare/strong_order.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions libcxx/include/__compare/weak_order.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/__iterator/iter_move.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 2 additions & 4 deletions libcxx/include/__ranges/access.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down
3 changes: 1 addition & 2 deletions libcxx/include/__ranges/rbegin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 1 addition & 2 deletions libcxx/include/__ranges/rend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 1 addition & 2 deletions libcxx/include/__ranges/size.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>>;
Expand Down
4 changes: 2 additions & 2 deletions libcxx/include/version
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*/

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -255,8 +255,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_ssize
Expand Down Expand Up @@ -313,8 +313,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_ssize
Expand Down
Loading
Loading