Revert "[clang-tidy] modernize-use-override new option AllowOverrideAndFinal"
authorMitchell Balan <mitchell@stellarscience.com>
Tue, 19 Nov 2019 12:43:12 +0000 (07:43 -0500)
committerMitchell Balan <mitchell@stellarscience.com>
Tue, 19 Nov 2019 12:52:31 +0000 (07:52 -0500)
This reverts commit 50e99563fb0459f5160572eef3c4e6062b8ad3f2.

clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init-msvc.cpp
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp

index 6bf0edb7231fa5f47cc46c7b25db724580b0d3d8..42f802cd0af451d80d390c2fe468040e3a4a8ee0 100644 (file)
@@ -73,7 +73,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"),
@@ -82,12 +82,11 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
 }
 
 void RedundantStringInitCheck::check(const MatchFinder::MatchResult &Result) {
-  const auto *VDecl = Result.Nodes.getNodeAs<VarDecl>("vardecl");
-  // VarDecl's getSourceRange() spans 'string foo = ""' or 'string bar("")'.
-  // So start at getLocation() to span just 'foo = ""' or 'bar("")'.
-  SourceRange ReplaceRange(VDecl->getLocation(), VDecl->getEndLoc());
-  diag(VDecl->getLocation(), "redundant string initialization")
-      << FixItHint::CreateReplacement(ReplaceRange, VDecl->getName());
+  const auto *CtorExpr = Result.Nodes.getNodeAs<Expr>("expr");
+  const auto *Decl = Result.Nodes.getNodeAs<NamedDecl>("decl");
+  diag(CtorExpr->getExprLoc(), "redundant string initialization")
+      << FixItHint::CreateReplacement(CtorExpr->getSourceRange(),
+                                      Decl->getName());
 }
 
 } // namespace readability
index 0299519a508efcc70132b314286279cef1ca998a..fe05845db6639c0de28db2378368e65b2792cfe1 100644 (file)
@@ -1,4 +1,5 @@
-// RUN: %check_clang_tidy %s readability-redundant-string-init %t
+// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t
+// FIXME: Fix the checker to work in C++17 mode.
 
 namespace std {
 template <typename T>
index 15df753ece33c82611d9747faa61078a002f167d..f8e9754535478ae7c783b6680b91819aaa53c74b 100644 (file)
@@ -1,8 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t \
-// RUN:   -config="{CheckOptions: \
-// RUN:             [{key: readability-redundant-string-init.StringNames, \
-// RUN:               value: '::std::basic_string;our::TestString'}] \
-// RUN:             }"
+// RUN: %check_clang_tidy -std=c++11,c++14 %s readability-redundant-string-init %t
 // FIXME: Fix the checker to work in C++17 mode.
 
 namespace std {
@@ -135,11 +131,6 @@ void k() {
   // CHECK-FIXES: std::string a, b, c;
 
   std::string d = "u", e = "u", f = "u";
-
-  std::string g = "u", h = "", i = "uuu", j = "", k;
-  // CHECK-MESSAGES: [[@LINE-1]]:24: warning: redundant string initialization
-  // CHECK-MESSAGES: [[@LINE-2]]:43: warning: redundant string initialization
-  // CHECK-FIXES: std::string g = "u", h, i = "uuu", j, k;
 }
 
 // These cases should not generate warnings.