[clang-tools-extra] [clang-tidy] Correct `std::has_one_bit` to `std::has_single_bit` in `modernize-use-std-bit` (PR #196721)

2026-05-09 Thread via cfe-commits

https://github.com/flovent created 
https://github.com/llvm/llvm-project/pull/196721

There isn't `std::has_one_bit` in standard library, the function checks if a 
number is an integral power of 2 is `std::has_single_bit`.

https://en.cppreference.com/cpp/header/bit

>From 1800fa4deb594408ec514ddcbc4fb814f9d30493 Mon Sep 17 00:00:00 2001
From: flovent 
Date: Sat, 9 May 2026 21:06:18 +0800
Subject: [PATCH] [clang-tidy] Correct `std::has_one_bit` to
 `std::has_single_bit` in `modernize-use-std-bit`

---
 .../clang-tidy/modernize/UseStdBitCheck.cpp   | 11 ++--
 .../checks/modernize/use-std-bit.rst  | 12 ++---
 .../checkers/modernize/use-std-bit.cpp| 50 +--
 3 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
index 0abe7d6323bdf..b534757e89434 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
@@ -71,13 +71,13 @@ void UseStdBitCheck::registerMatchers(MatchFinder *Finder) {
   };
 
   // Determining if an integer is a power of 2 with following pattern:
-  // has_one_bit(v) = v && !(v & (v - 1));
+  // has_single_bit(v) = v && !(v & (v - 1));
   Finder->addMatcher(
   LogicalAnd(IsNonNull(BindDeclRef("v")),
  LogicalNot(BitwiseAnd(
  BoundDeclRef("v"),
  Sub(BoundDeclRef("v"), integerLiteral(equals(1))
-  .bind("has_one_bit_expr"),
+  .bind("has_single_bit_expr"),
   this);
 
   // Computing popcount with following pattern:
@@ -120,16 +120,17 @@ void UseStdBitCheck::check(const MatchFinder::MatchResult 
&Result) {
   const SourceManager &Source = Context.getSourceManager();
 
   if (const auto *MatchedExpr =
-  Result.Nodes.getNodeAs("has_one_bit_expr")) {
+  Result.Nodes.getNodeAs("has_single_bit_expr")) {
 const auto *MatchedVarDecl = Result.Nodes.getNodeAs("v");
 
 auto Diag =
-diag(MatchedExpr->getBeginLoc(), "use 'std::has_one_bit' instead");
+diag(MatchedExpr->getBeginLoc(), "use 'std::has_single_bit' instead");
 if (auto R = MatchedExpr->getSourceRange();
 !R.getBegin().isMacroID() && !R.getEnd().isMacroID()) {
   Diag << FixItHint::CreateReplacement(
   MatchedExpr->getSourceRange(),
-  ("std::has_one_bit(" + MatchedVarDecl->getName() + 
")").str())
+  ("std::has_single_bit(" + MatchedVarDecl->getName() + ")")
+  .str())
<< IncludeInserter.createIncludeInsertion(
   Source.getFileID(MatchedExpr->getBeginLoc()), "");
 }
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
index 36848b7e3d228..9f90c1aa06cec 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
@@ -8,16 +8,16 @@ Finds common idioms which can be replaced by standard 
functions from the
 
 Covered scenarios:
 
-== ===
+== ==
 Expression Replacement
--- ---
-``x && !(x & (x - 1))````std::has_one_bit(x)``
-``(x != 0) && !(x & (x - 1))`` ``std::has_one_bit(x)``
-``(x > 0) && !(x & (x - 1))``  ``std::has_one_bit(x)``
+-- --
+``x && !(x & (x - 1))````std::has_single_bit(x)``
+``(x != 0) && !(x & (x - 1))`` ``std::has_single_bit(x)``
+``(x > 0) && !(x & (x - 1))``  ``std::has_single_bit(x)``
 ``std::bitset(x).count()``  ``std::popcount(x)``
 ``x << 3 | x >> 61``   ``std::rotl(x, 3)``
 ``x << 61 | x >> 3``   ``std::rotr(x, 3)``
-== ===
+== ==
 
 Options
 ---
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
index 615d1202e8092..d1ca194424d20 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
@@ -6,80 +6,80 @@
  * has_one_bit pattern
  */
 unsigned has_one_bit_bithack(unsigned x) {
-  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::has_one_bit' instead 
[modernize-use-std-bit]
-  // CHECK-FIXES: return std::has_one_bit(x);
+  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::has_single_bit' 
instead [modernize-use-std-bit]
+  // CHECK-FIXES: return std::has_single_bit(x);
   return x && !(x & (x - 1));
 }
 
 unsigned long has_one_bit_bithack(unsigned long x) {
-  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use

[clang-tools-extra] [clang-tidy] Correct `std::has_one_bit` to `std::has_single_bit` in `modernize-use-std-bit` (PR #196721)

2026-05-09 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang-tidy

Author: flovent


Changes

There isn't `std::has_one_bit` in standard library, the function checks if a 
number is an integral power of 2 is `std::has_single_bit`.

https://en.cppreference.com/cpp/header/bit

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp (+6-5) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst 
(+6-6) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp (+25-25) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
index 0abe7d6323bdf..b534757e89434 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
@@ -71,13 +71,13 @@ void UseStdBitCheck::registerMatchers(MatchFinder *Finder) {
   };
 
   // Determining if an integer is a power of 2 with following pattern:
-  // has_one_bit(v) = v && !(v & (v - 1));
+  // has_single_bit(v) = v && !(v & (v - 1));
   Finder->addMatcher(
   LogicalAnd(IsNonNull(BindDeclRef("v")),
  LogicalNot(BitwiseAnd(
  BoundDeclRef("v"),
  Sub(BoundDeclRef("v"), integerLiteral(equals(1))
-  .bind("has_one_bit_expr"),
+  .bind("has_single_bit_expr"),
   this);
 
   // Computing popcount with following pattern:
@@ -120,16 +120,17 @@ void UseStdBitCheck::check(const MatchFinder::MatchResult 
&Result) {
   const SourceManager &Source = Context.getSourceManager();
 
   if (const auto *MatchedExpr =
-  Result.Nodes.getNodeAs("has_one_bit_expr")) {
+  Result.Nodes.getNodeAs("has_single_bit_expr")) {
 const auto *MatchedVarDecl = Result.Nodes.getNodeAs("v");
 
 auto Diag =
-diag(MatchedExpr->getBeginLoc(), "use 'std::has_one_bit' instead");
+diag(MatchedExpr->getBeginLoc(), "use 'std::has_single_bit' instead");
 if (auto R = MatchedExpr->getSourceRange();
 !R.getBegin().isMacroID() && !R.getEnd().isMacroID()) {
   Diag << FixItHint::CreateReplacement(
   MatchedExpr->getSourceRange(),
-  ("std::has_one_bit(" + MatchedVarDecl->getName() + 
")").str())
+  ("std::has_single_bit(" + MatchedVarDecl->getName() + ")")
+  .str())
<< IncludeInserter.createIncludeInsertion(
   Source.getFileID(MatchedExpr->getBeginLoc()), "");
 }
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
index 36848b7e3d228..9f90c1aa06cec 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
@@ -8,16 +8,16 @@ Finds common idioms which can be replaced by standard 
functions from the
 
 Covered scenarios:
 
-== ===
+== ==
 Expression Replacement
--- ---
-``x && !(x & (x - 1))````std::has_one_bit(x)``
-``(x != 0) && !(x & (x - 1))`` ``std::has_one_bit(x)``
-``(x > 0) && !(x & (x - 1))``  ``std::has_one_bit(x)``
+-- --
+``x && !(x & (x - 1))````std::has_single_bit(x)``
+``(x != 0) && !(x & (x - 1))`` ``std::has_single_bit(x)``
+``(x > 0) && !(x & (x - 1))``  ``std::has_single_bit(x)``
 ``std::bitset(x).count()``  ``std::popcount(x)``
 ``x << 3 | x >> 61``   ``std::rotl(x, 3)``
 ``x << 61 | x >> 3``   ``std::rotr(x, 3)``
-== ===
+== ==
 
 Options
 ---
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
index 615d1202e8092..d1ca194424d20 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
@@ -6,80 +6,80 @@
  * has_one_bit pattern
  */
 unsigned has_one_bit_bithack(unsigned x) {
-  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::has_one_bit' instead 
[modernize-use-std-bit]
-  // CHECK-FIXES: return std::has_one_bit(x);
+  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::has_single_bit' 
instead [modernize-use-std-bit]
+  // CHECK-FIXES: return std::has_single_bit(x);
   return x && !(x & (x - 1));
 }
 
 unsigned long has_one_bit_bithack(unsigned long x) {
-  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::has_one_bit' instead 
[modernize-use-std-bit]
-  // CHECK-FIXES: return std::has_one_bit(x)

[clang-tools-extra] [clang-tidy] Correct `std::has_one_bit` to `std::has_single_bit` in `modernize-use-std-bit` (PR #196721)

2026-05-09 Thread Zeyi Xu via cfe-commits

https://github.com/zeyi2 approved this pull request.


https://github.com/llvm/llvm-project/pull/196721
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Correct `std::has_one_bit` to `std::has_single_bit` in `modernize-use-std-bit` (PR #196721)

2026-05-09 Thread via cfe-commits

llvmorg-github-actions[bot] wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: flovent


Changes

There isn't `std::has_one_bit` in standard library, the function checks if a 
number is an integral power of 2 is `std::has_single_bit`.

https://en.cppreference.com/cpp/header/bit

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp (+6-5) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst 
(+6-6) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp (+25-25) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
index 0abe7d6323bdf..b534757e89434 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdBitCheck.cpp
@@ -71,13 +71,13 @@ void UseStdBitCheck::registerMatchers(MatchFinder *Finder) {
   };
 
   // Determining if an integer is a power of 2 with following pattern:
-  // has_one_bit(v) = v && !(v & (v - 1));
+  // has_single_bit(v) = v && !(v & (v - 1));
   Finder->addMatcher(
   LogicalAnd(IsNonNull(BindDeclRef("v")),
  LogicalNot(BitwiseAnd(
  BoundDeclRef("v"),
  Sub(BoundDeclRef("v"), integerLiteral(equals(1))
-  .bind("has_one_bit_expr"),
+  .bind("has_single_bit_expr"),
   this);
 
   // Computing popcount with following pattern:
@@ -120,16 +120,17 @@ void UseStdBitCheck::check(const MatchFinder::MatchResult 
&Result) {
   const SourceManager &Source = Context.getSourceManager();
 
   if (const auto *MatchedExpr =
-  Result.Nodes.getNodeAs("has_one_bit_expr")) {
+  Result.Nodes.getNodeAs("has_single_bit_expr")) {
 const auto *MatchedVarDecl = Result.Nodes.getNodeAs("v");
 
 auto Diag =
-diag(MatchedExpr->getBeginLoc(), "use 'std::has_one_bit' instead");
+diag(MatchedExpr->getBeginLoc(), "use 'std::has_single_bit' instead");
 if (auto R = MatchedExpr->getSourceRange();
 !R.getBegin().isMacroID() && !R.getEnd().isMacroID()) {
   Diag << FixItHint::CreateReplacement(
   MatchedExpr->getSourceRange(),
-  ("std::has_one_bit(" + MatchedVarDecl->getName() + 
")").str())
+  ("std::has_single_bit(" + MatchedVarDecl->getName() + ")")
+  .str())
<< IncludeInserter.createIncludeInsertion(
   Source.getFileID(MatchedExpr->getBeginLoc()), "");
 }
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
index 36848b7e3d228..9f90c1aa06cec 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-bit.rst
@@ -8,16 +8,16 @@ Finds common idioms which can be replaced by standard 
functions from the
 
 Covered scenarios:
 
-== ===
+== ==
 Expression Replacement
--- ---
-``x && !(x & (x - 1))````std::has_one_bit(x)``
-``(x != 0) && !(x & (x - 1))`` ``std::has_one_bit(x)``
-``(x > 0) && !(x & (x - 1))``  ``std::has_one_bit(x)``
+-- --
+``x && !(x & (x - 1))````std::has_single_bit(x)``
+``(x != 0) && !(x & (x - 1))`` ``std::has_single_bit(x)``
+``(x > 0) && !(x & (x - 1))``  ``std::has_single_bit(x)``
 ``std::bitset(x).count()``  ``std::popcount(x)``
 ``x << 3 | x >> 61``   ``std::rotl(x, 3)``
 ``x << 61 | x >> 3``   ``std::rotr(x, 3)``
-== ===
+== ==
 
 Options
 ---
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
index 615d1202e8092..d1ca194424d20 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-bit.cpp
@@ -6,80 +6,80 @@
  * has_one_bit pattern
  */
 unsigned has_one_bit_bithack(unsigned x) {
-  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::has_one_bit' instead 
[modernize-use-std-bit]
-  // CHECK-FIXES: return std::has_one_bit(x);
+  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::has_single_bit' 
instead [modernize-use-std-bit]
+  // CHECK-FIXES: return std::has_single_bit(x);
   return x && !(x & (x - 1));
 }
 
 unsigned long has_one_bit_bithack(unsigned long x) {
-  // CHECK-MESSAGES: :[[@LINE+2]]:10: warning: use 'std::has_one_bit' instead 
[modernize-use-std-bit]
-  // CHECK-FIXES: return std::has_one

[clang-tools-extra] [clang-tidy] Correct `std::has_one_bit` to `std::has_single_bit` in `modernize-use-std-bit` (PR #196721)

2026-05-09 Thread via cfe-commits

https://github.com/flovent closed 
https://github.com/llvm/llvm-project/pull/196721
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Correct `std::has_one_bit` to `std::has_single_bit` in `modernize-use-std-bit` (PR #196721)

2026-05-09 Thread Daniil Dudkin via cfe-commits

https://github.com/unterumarmung approved this pull request.


https://github.com/llvm/llvm-project/pull/196721
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits