[libcxx-commits] [libcxx] [libc++] Prevent calling the projection more than three times (PR #66315)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 13 23:33:05 PDT 2023
================
@@ -37,9 +37,10 @@ struct __fn {
_LIBCPP_ASSERT_UNCATEGORIZED(!bool(std::invoke(__comp, std::invoke(__proj, __high), std::invoke(__proj, __low))),
"Bad bounds passed to std::ranges::clamp");
- if (std::invoke(__comp, std::invoke(__proj, __value), std::invoke(__proj, __low)))
+ auto& ValueProjection = std::invoke(__proj, __value);
----------------
frederick-vs-ja wrote:
A reserved identifier like `__projected_value` is needed. A well-defined program can `#define ValueProjection 42`, because `ValueProjection` is unreserved, and then causes error in this line.
Moreover, `auto&` is incorrect because `std::invoke(__proj, __value)` may be an rvalue. `auto&&` or `decltype(auto)` should be used and then the result should be `std::forward`'d in later invocations.
https://github.com/llvm/llvm-project/pull/66315
More information about the libcxx-commits
mailing list