[clang-tools-extra] [clang-tidy] Detect std::rot[lr] pattern within modernize.use-std-bit (PR #186324)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 13 02:30:43 PDT 2026


================
@@ -195,3 +195,59 @@ unsigned invalid_popcount_bitset(unsigned x, signed y) {
   };
 }
 
+
+/*
+ * rotate patterns
+ */
+unsigned char rotate_left_pattern(unsigned char x) {
+  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::rotl' instead [modernize-use-std-bit]
+  // CHECK-FIXES: return (int)std::rotl(x, 3);
----------------
localspook wrote:

I think it may be better to just not bother with adding the `int` cast. In most cases, it's just noise. Yes, not adding it means that you could come up with a pathological case where the fix-it changes program semantics, but I think we should optimize for the common case, where it's not needed.

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


More information about the cfe-commits mailing list