Skip to content

Commit 7145f89

Browse files
authored
[clang-tidy] Emit deprecation warning for preformance-faster-string-find (llvm#191922)
Related discussion in: llvm#186946 (comment)
1 parent 7ae5fe6 commit 7145f89

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "PreferSingleCharOverloadsCheck.h"
10+
#include "../utils/CheckUtils.h"
1011
#include "../utils/OptionsUtils.h"
1112
#include "clang/ASTMatchers/ASTMatchFinder.h"
1213
#include "llvm/Support/raw_ostream.h"
@@ -16,6 +17,15 @@ using namespace clang::ast_matchers;
1617

1718
namespace clang::tidy::performance {
1819

20+
namespace {
21+
22+
constexpr llvm::StringLiteral DeprecatedCheckName =
23+
"performance-faster-string-find";
24+
constexpr llvm::StringLiteral CanonicalCheckName =
25+
"performance-prefer-single-char-overloads";
26+
27+
} // namespace
28+
1929
static std::optional<std::string>
2030
makeCharacterLiteral(const StringLiteral *Literal) {
2131
std::string Result;
@@ -46,7 +56,11 @@ PreferSingleCharOverloadsCheck::PreferSingleCharOverloadsCheck(
4656
: ClangTidyCheck(Name, Context),
4757
StringLikeClasses(utils::options::parseStringList(
4858
Options.get("StringLikeClasses",
49-
"::std::basic_string;::std::basic_string_view"))) {}
59+
"::std::basic_string;::std::basic_string_view"))) {
60+
if (Name == DeprecatedCheckName)
61+
utils::diagDeprecatedCheckAlias(*this, *Context, DeprecatedCheckName,
62+
CanonicalCheckName);
63+
}
5064

5165
void PreferSingleCharOverloadsCheck::storeOptions(
5266
ClangTidyOptions::OptionMap &Opts) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %check_clang_tidy %s performance-faster-string-find %t
2+
3+
#include <string>
4+
5+
void stringFind() {
6+
std::string Str;
7+
Str.find("a");
8+
// 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]
9+
// 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]
10+
// CHECK-FIXES: Str.find('a');
11+
}

0 commit comments

Comments
 (0)