aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
diff options
context:
space:
mode:
authorMitchell Balan <mitchell@stellarscience.com>2019-11-15 16:46:58 -0500
committerMitchell Balan <mitchell@stellarscience.com>2019-11-15 16:46:58 -0500
commit47bd7c57e556e3a4db51566d59c2d796ce898c8f (patch)
tree92c8a22499f3a8534f554fd636e4dbfa374acc6e /clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
parent96fbc32cb9ea23b1e7e3ff6906ec3ccda9500982 (diff)
downloadllvm-47bd7c57e556e3a4db51566d59c2d796ce898c8f.zip
llvm-47bd7c57e556e3a4db51566d59c2d796ce898c8f.tar.gz
llvm-47bd7c57e556e3a4db51566d59c2d796ce898c8f.tar.bz2
Revert "[clang-tidy] Give readability-redundant-string-init a customizable list of string types to fix"
This reverts commit 96fbc32cb9ea23b1e7e3ff6906ec3ccda9500982.
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp43
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"),