Fix use of directly-nested traverse() matchers
authorStephen Kelly <steveire@gmail.com>
Mon, 9 Nov 2020 18:59:30 +0000 (18:59 +0000)
committerStephen Kelly <steveire@gmail.com>
Mon, 9 Nov 2020 19:23:17 +0000 (19:23 +0000)
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

index b6934c6..f556397 100644 (file)
@@ -1206,6 +1206,8 @@ public:
   }
 
   llvm::Optional<clang::TraversalKind> TraversalKind() const override {
+    if (auto NestedKind = this->InnerMatcher.getTraversalKind())
+      return NestedKind;
     return Traversal;
   }
 };
index c7ce63c..0d06bdc 100644 (file)
@@ -2372,6 +2372,11 @@ void foo()
                              callExpr(has(callExpr(traverse(
                                  TK_AsIs, callExpr(has(implicitCastExpr(
                                               has(floatLiteral())))))))))));
+
+  EXPECT_TRUE(matches(
+      Code,
+      traverse(TK_IgnoreImplicitCastsAndParentheses,
+               traverse(TK_AsIs, implicitCastExpr(has(floatLiteral()))))));
 }
 
 TEST(Traversal, traverseMatcherThroughImplicit) {