[clang-tidy] Emit deprecation warning for preformance-faster-string-find (#191922)
Related discussion in: https://github.com/llvm/llvm-project/pull/186946#discussion_r2983649044
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
Reference in New Issue
Block a user