[PATCH] D69238: Fix clang-tidy readability-redundant-string-init for c++17/c++2a

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 28 08:48:28 PDT 2019


aaron.ballman added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp:75
+// and if found, extend the SourceRange to start at 'Name'.
+std::pair<clang::SourceRange, bool>
+CtorSourceRange(const MatchFinder::MatchResult &Result,
----------------
You can drop the `clang::` everywhere -- the code is within the correct namespace already.


================
Comment at: clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp:79-80
+  const SourceManager &SM = *Result.SourceManager;
+  const StringRef Name = Decl->getName();
+  const int NameLength = Name.size();
+  const SourceLocation CtorStartLoc(CtorExpr->getSourceRange().getBegin());
----------------
Please drop top-level `const` qualifiers unless it's a pointer or reference declaration (that's not a style we typically use).


================
Comment at: clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp:128
+      diag(CtorExprRange.first.getBegin(), "redundant string initialization");
+  if (CtorExprRange.second) {
+    Diag << FixItHint::CreateReplacement(CtorExprRange.first, Decl->getName());
----------------
Elide braces per coding style.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp:106
   DECL_STRING(e, "");
-  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-1]]:1{{[58]}}: warning: redundant string initialization
 
----------------
Why does this need a regex?


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69238/new/

https://reviews.llvm.org/D69238





More information about the cfe-commits mailing list