[llvm] [Support] Use "if constexpr" in shouldReverseIterate (PR #156812)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 3 23:28:04 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

This patch simplifies shouldReverseIterate with "if constexpr" while
switching to "constexpr bool", allowing compile-time evaluation at
call sites.


---
Full diff: https://github.com/llvm/llvm-project/pull/156812.diff


1 Files Affected:

- (modified) llvm/include/llvm/Support/ReverseIteration.h (+5-7) 


``````````diff
diff --git a/llvm/include/llvm/Support/ReverseIteration.h b/llvm/include/llvm/Support/ReverseIteration.h
index 9e9411856369e..456d423600d6e 100644
--- a/llvm/include/llvm/Support/ReverseIteration.h
+++ b/llvm/include/llvm/Support/ReverseIteration.h
@@ -6,13 +6,11 @@
 
 namespace llvm {
 
-template<class T = void *>
-bool shouldReverseIterate() {
-#if LLVM_ENABLE_REVERSE_ITERATION
-  return detail::IsPointerLike<T>::value;
-#else
-  return false;
-#endif
+template <class T = void *> constexpr bool shouldReverseIterate() {
+  if constexpr (LLVM_ENABLE_REVERSE_ITERATION)
+    return detail::IsPointerLike<T>::value;
+  else
+    return false;
 }
 
 } // namespace llvm

``````````

</details>


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


More information about the llvm-commits mailing list