[clang-tools-extra] 5e9392d - Add explicit traversal mode to matchers for implicit constructors

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Sun May 24 04:37:11 PDT 2020


Author: Stephen Kelly
Date: 2020-05-24T12:36:15+01:00
New Revision: 5e9392deaf5bfa43846334e9b07a126ae3410a38

URL: https://github.com/llvm/llvm-project/commit/5e9392deaf5bfa43846334e9b07a126ae3410a38
DIFF: https://github.com/llvm/llvm-project/commit/5e9392deaf5bfa43846334e9b07a126ae3410a38.diff

LOG: Add explicit traversal mode to matchers for implicit constructors

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
    clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp
    clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
index 1c47f17d8a64..96d93a1d0413 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -100,10 +100,11 @@ void StringConstructorCheck::registerMatchers(MatchFinder *Finder) {
   // Check the literal string constructor with char pointer.
   // [i.e. string (const char* s);]
   Finder->addMatcher(
+    traverse(TK_AsIs,
       cxxConstructExpr(hasDeclaration(cxxMethodDecl(hasName("basic_string"))),
                        hasArgument(0, expr().bind("from-ptr")),
                        hasArgument(1, unless(hasType(isInteger()))))
-          .bind("constructor"),
+          .bind("constructor")),
       this);
 }
 

diff  --git a/clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp
index 815062618a97..b533db760d5e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringLiteralWithEmbeddedNulCheck.cpp
@@ -49,8 +49,8 @@ void StringLiteralWithEmbeddedNulCheck::registerMatchers(MatchFinder *Finder) {
 
   // Detect passing a suspicious string literal to a string constructor.
   // example: std::string str = "abc\0def";
-  Finder->addMatcher(
-      cxxConstructExpr(StringConstructorExpr, hasArgument(0, StrLitWithNul)),
+  Finder->addMatcher(traverse(TK_AsIs,
+      cxxConstructExpr(StringConstructorExpr, hasArgument(0, StrLitWithNul))),
       this);
 
   // Detect passing a suspicious string literal through an overloaded operator.

diff  --git a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
index 78bf744eba8d..e5825bc4f0e3 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -96,8 +96,9 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
 
   const auto StringType = hasType(hasUnqualifiedDesugaredType(
       recordType(hasDeclaration(cxxRecordDecl(hasStringTypeName)))));
-  const auto EmptyStringInit = expr(ignoringImplicit(
-      anyOf(EmptyStringCtorExpr, EmptyStringCtorExprWithTemporaries)));
+  const auto EmptyStringInit =
+      traverse(ast_type_traits::TK_AsIs, expr(ignoringImplicit(
+      anyOf(EmptyStringCtorExpr, EmptyStringCtorExprWithTemporaries))));
 
   // Match a variable declaration with an empty string literal as initializer.
   // Examples:


        


More information about the cfe-commits mailing list