[clang-tools-extra] [clang-tidy] Detect std::popcount opportunity within modernize.use-std-bit (PR #185740)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 11 00:06:48 PDT 2026


================
@@ -111,7 +114,69 @@ unsigned invalid_bithacks(integer_like w, unsigned x, signed y, unsigned z) {
 }
 
 template <class T>
-T bithacks_generic(T x) {
-  // substitution only valid for some instantiation of bithacks_generic
+T has_one_bit_bithack_generic(T x) {
+  // substitution only valid for some instantiation of has_one_bit_bithack_generic
   return x && !(x & (x - 1));
 }
+
+/*
+ * popcount pattern
+ */
+namespace std {
+using size_t = decltype(sizeof(0));
+template<size_t N> class bitset {
+  public:
+  bitset(unsigned long);
----------------
localspook wrote:

Nit: this should technically be:
```suggestion
  bitset(unsigned long long);
```

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


More information about the cfe-commits mailing list