[libcxx-commits] [libcxx] [libc++] Fix complexity guarantee in std::clamp (PR #68413)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 10 10:43:49 PDT 2023


================
@@ -82,31 +93,29 @@ constexpr bool test() {
     auto low = S{20};
     auto high = S{30};
     // Check that the value category of the projection return type is preserved.
-    assert(&std::ranges::clamp(val, low, high, Comp{}, &S::lvalue_proj) == &low);
----------------
ldionne wrote:

This PR was lifted from https://github.com/llvm/llvm-project/pull/66315 which was closed unexpectedly, and the discussion over there explain it. Not replicating the full story here cause it's kind of complicated.

But long story short, the potential-double-moving is mandated by the standard (and if it is harmful then the projection is not equality-preserving, which means that the user did something bad -- it's still wacky that we can't diagnose it at compile-time). So these tests were in fact wrong from the start.

https://github.com/llvm/llvm-project/pull/68413


More information about the libcxx-commits mailing list