
This PR aims to expand the list of classes that are considered to be "strings" by `readability-string-compare` check. 1. Currently only `std::string;:compare` is checked, but `std::string_view` has a similar `compare` method. This PR enables checking of `std::string_view::compare` by default. 2. Some codebases use custom string-like classes that have public interfaces similar to `std::string` or `std::string_view`. Example: [TStringBase](https://github.com/yandex/yatool/blob/main/util/generic/strbase.h#L38), A new option, `readability-string-compare.StringClassNames`, is added to allow specifying a custom list of string-like classes. Related to, but does not solve #28396 (only adds support for custom string-like classes, not custom functions)
41 lines
1.4 KiB
C++
41 lines
1.4 KiB
C++
//===--- StringCompareCheck.h - clang-tidy-----------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STRINGCOMPARECHECK_H
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STRINGCOMPARECHECK_H
|
|
|
|
#include "../ClangTidyCheck.h"
|
|
#include <vector>
|
|
|
|
namespace clang::tidy::readability {
|
|
|
|
/// This check flags all calls compare when used to check for string
|
|
/// equality or inequality.
|
|
///
|
|
/// For the user-facing documentation see:
|
|
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/string-compare.html
|
|
class StringCompareCheck : public ClangTidyCheck {
|
|
public:
|
|
StringCompareCheck(StringRef Name, ClangTidyContext *Context);
|
|
|
|
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
|
|
return LangOpts.CPlusPlus;
|
|
}
|
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
|
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
|
|
|
|
private:
|
|
const std::vector<StringRef> StringLikeClasses;
|
|
};
|
|
|
|
} // namespace clang::tidy::readability
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_STRINGCOMPARECHECK_H
|