Author: Zeyi Xu
Date: 2026-04-15T16:26:59+08:00
New Revision: 7145f8986a82df677e67493b47243fd65aac8653

URL: 
https://github.com/llvm/llvm-project/commit/7145f8986a82df677e67493b47243fd65aac8653
DIFF: 
https://github.com/llvm/llvm-project/commit/7145f8986a82df677e67493b47243fd65aac8653.diff

LOG: [clang-tidy] Emit deprecation warning for preformance-faster-string-find 
(#191922)

Related discussion in:
https://github.com/llvm/llvm-project/pull/186946#discussion_r2983649044

Added: 
    
clang-tools-extra/test/clang-tidy/checkers/performance/prefer-single-char-overloads-alias.cpp

Modified: 
    clang-tools-extra/clang-tidy/performance/PreferSingleCharOverloadsCheck.cpp

Removed: 
    


################################################################################
diff  --git 
a/clang-tools-extra/clang-tidy/performance/PreferSingleCharOverloadsCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/PreferSingleCharOverloadsCheck.cpp
index 661d5e3d6b911..c29fef3b71c5e 100644
--- 
a/clang-tools-extra/clang-tidy/performance/PreferSingleCharOverloadsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/performance/PreferSingleCharOverloadsCheck.cpp
@@ -7,6 +7,7 @@
 
//===----------------------------------------------------------------------===//
 
 #include "PreferSingleCharOverloadsCheck.h"
+#include "../utils/CheckUtils.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "llvm/Support/raw_ostream.h"
@@ -16,6 +17,15 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::performance {
 
+namespace {
+
+constexpr llvm::StringLiteral DeprecatedCheckName =
+    "performance-faster-string-find";
+constexpr llvm::StringLiteral CanonicalCheckName =
+    "performance-prefer-single-char-overloads";
+
+} // namespace
+
 static std::optional<std::string>
 makeCharacterLiteral(const StringLiteral *Literal) {
   std::string Result;
@@ -46,7 +56,11 @@ 
PreferSingleCharOverloadsCheck::PreferSingleCharOverloadsCheck(
     : ClangTidyCheck(Name, Context),
       StringLikeClasses(utils::options::parseStringList(
           Options.get("StringLikeClasses",
-                      "::std::basic_string;::std::basic_string_view"))) {}
+                      "::std::basic_string;::std::basic_string_view"))) {
+  if (Name == DeprecatedCheckName)
+    utils::diagDeprecatedCheckAlias(*this, *Context, DeprecatedCheckName,
+                                    CanonicalCheckName);
+}
 
 void PreferSingleCharOverloadsCheck::storeOptions(
     ClangTidyOptions::OptionMap &Opts) {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/prefer-single-char-overloads-alias.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/performance/prefer-single-char-overloads-alias.cpp
new file mode 100644
index 0000000000000..2c09acaf15ef7
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/performance/prefer-single-char-overloads-alias.cpp
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s performance-faster-string-find %t
+
+#include <string>
+
+void stringFind() {
+  std::string Str;
+  Str.find("a");
+  // CHECK-MESSAGES: warning: 'performance-faster-string-find' check is 
deprecated and will be removed in a future release; consider using 
'performance-prefer-single-char-overloads' instead [clang-tidy-config]
+  // CHECK-MESSAGES: [[@LINE-2]]:12: warning: 'find' called with a string 
literal consisting of a single character; consider using the more efficient 
overload accepting a character [performance-faster-string-find]
+  // CHECK-FIXES: Str.find('a');
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to