diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp index 6bf0edb..a140e17f 100644 --- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp @@ -8,7 +8,6 @@ #include "RedundantStringInitCheck.h" #include "../utils/Matchers.h" -#include "../utils/OptionsUtils.h" #include "clang/ASTMatchers/ASTMatchers.h" using namespace clang::ast_matchers; @@ -18,43 +17,19 @@ namespace clang { namespace tidy { namespace readability { -const char DefaultStringNames[] = "::std::basic_string"; - -RedundantStringInitCheck::RedundantStringInitCheck(StringRef Name, - ClangTidyContext *Context) - : ClangTidyCheck(Name, Context), - StringNames(utils::options::parseStringList( - Options.get("StringNames", DefaultStringNames))) {} - -void RedundantStringInitCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { - Options.store(Opts, "StringNames", DefaultStringNames); -} - void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) { if (!getLangOpts().CPlusPlus) return; - const auto hasStringTypeName = hasAnyName( - SmallVector<StringRef, 3>(StringNames.begin(), StringNames.end())); - - // Version of StringNames with namespaces removed - std::vector<std::string> stringNamesNoNamespace; - for (const std::string &name : StringNames) { - std::string::size_type colonPos = name.rfind(':'); - stringNamesNoNamespace.push_back( - name.substr(colonPos == std::string::npos ? 0 : colonPos + 1)); - } - const auto hasStringCtorName = hasAnyName(SmallVector<StringRef, 3>( - stringNamesNoNamespace.begin(), stringNamesNoNamespace.end())); // Match string constructor. - const auto StringConstructorExpr = expr( - anyOf(cxxConstructExpr(argumentCountIs(1), - hasDeclaration(cxxMethodDecl(hasStringCtorName))), - // If present, the second argument is the alloc object which must - // not be present explicitly. - cxxConstructExpr(argumentCountIs(2), - hasDeclaration(cxxMethodDecl(hasStringCtorName)), - hasArgument(1, cxxDefaultArgExpr())))); + const auto StringConstructorExpr = expr(anyOf( + cxxConstructExpr(argumentCountIs(1), + hasDeclaration(cxxMethodDecl(hasName("basic_string")))), + // If present, the second argument is the alloc object which must not + // be present explicitly. + cxxConstructExpr(argumentCountIs(2), + hasDeclaration(cxxMethodDecl(hasName("basic_string"))), + hasArgument(1, cxxDefaultArgExpr())))); // Match a string constructor expression with an empty string literal. const auto EmptyStringCtorExpr = cxxConstructExpr( @@ -73,7 +48,7 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) { namedDecl( varDecl( hasType(hasUnqualifiedDesugaredType(recordType( - hasDeclaration(cxxRecordDecl(hasStringTypeName))))), + hasDeclaration(cxxRecordDecl(hasName("basic_string")))))), hasInitializer(expr(ignoringImplicit(anyOf( EmptyStringCtorExpr, EmptyStringCtorExprWithTemporaries))))) .bind("vardecl"), |