[libc-commits] [libc] [libc++] Prevent calling the projection more than three times (PR #66315)

Louis Dionne via libc-commits libc-commits at lists.llvm.org
Fri Sep 15 13:05:23 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&& __projected = std::forward<decltype(__projected)>(std::invoke(__proj, __value));
+    if (std::invoke(__comp, __projected), std::invoke(__proj, __low)))
----------------
ldionne wrote:

```suggestion
    if (std::invoke(__comp, __projected, std::invoke(__proj, __low)))
```

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


More information about the libc-commits mailing list