diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -194,7 +194,7 @@ DeclarationMatcher HasClassX = recordDecl(has(recordDecl(hasName("X")))); EXPECT_TRUE(matches("class Y { class X {}; };", HasClassX)); - EXPECT_TRUE(matches("class X {};", HasClassX)); + EXPECT_TRUE(matches("class X {};", traverse(TK_AsIs, HasClassX))); DeclarationMatcher YHasClassX = recordDecl(hasName("Y"), has(recordDecl(hasName("X")))); @@ -265,12 +265,14 @@ return; } - DeclarationMatcher Recursive = recordDecl( - anyOf(has(recordDecl(anyOf(has(recordDecl(hasName("X"))), - has(recordDecl(hasName("Y"))), hasName("Z")))), - has(recordDecl(anyOf(hasName("C"), has(recordDecl(hasName("A"))), - has(recordDecl(hasName("B")))))), - hasName("F"))); + DeclarationMatcher Recursive = traverse( + TK_AsIs, + recordDecl(anyOf( + has(recordDecl(anyOf(has(recordDecl(hasName("X"))), + has(recordDecl(hasName("Y"))), hasName("Z")))), + has(recordDecl(anyOf(hasName("C"), has(recordDecl(hasName("A"))), + has(recordDecl(hasName("B")))))), + hasName("F")))); EXPECT_TRUE(matches("class F {};", Recursive)); EXPECT_TRUE(matches("class Z {};", Recursive)); @@ -540,26 +542,26 @@ EXPECT_TRUE( matches("template class A { public: class Z : public X {}; }; " "class X{}; void y() { A::Z z; }", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE( matches("template class X {}; " "template class A { class Z : public X {}; };", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE(notMatches("template class X> class A { " " class Z : public X {}; };", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE(matches("template class X> class A { " " public: class Z : public X {}; }; " "template class X {}; void y() { A::Z z; }", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE( notMatches("template class A { class Z : public X::D {}; };", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE(matches("template class A { public: " " class Z : public X::D {}; }; " "class Y { public: class X {}; typedef X D; }; " "void y() { A::Z z; }", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE(matches("class X {}; typedef X Y; class Z : public Y {};", ZIsDerivedFromX)); EXPECT_TRUE(matches("template class Y { typedef typename T::U X; " @@ -574,10 +576,10 @@ matches("template class X { public: typedef X D; }; " "template class A { public: " " class Z : public X::D {}; }; void y() { A::Z z; }", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE( notMatches("template class A { class Z : public X::D::E {}; };", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE( matches("class X {}; typedef X V; typedef V W; class Z : public W {};", ZIsDerivedFromX)); @@ -590,11 +592,11 @@ EXPECT_TRUE( matches("template class X {}; " "template class A { class Z : public X {}; };", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE( notMatches("template class D { typedef X A; typedef A B; " " typedef B C; class Z : public C {}; };", - ZIsDerivedFromX)); + traverse(TK_AsIs, ZIsDerivedFromX))); EXPECT_TRUE(matches("class X {}; typedef X A; typedef A B; " "class Z : public B {};", ZIsDerivedFromX)); @@ -619,36 +621,38 @@ EXPECT_TRUE(notMatches("template class Z;" "template <> class Z {};" "template class Z : public Z {};", - IsDerivedFromX)); + traverse(TK_AsIs, IsDerivedFromX))); EXPECT_TRUE(matches("template class X;" "template <> class X {};" "template class X : public X {};", - IsDerivedFromX)); + traverse(TK_AsIs, IsDerivedFromX))); EXPECT_TRUE( matches("class X {};" "template class Z;" "template <> class Z {};" "template class Z : public Z, public X {};", - ZIsDerivedFromX)); - EXPECT_TRUE( - notMatches("template struct X;" - "template struct X : public X {};", - cxxRecordDecl(isDerivedFrom(recordDecl(hasName("Some")))))); + traverse(TK_AsIs, ZIsDerivedFromX))); + EXPECT_TRUE(notMatches("template struct X;" + "template struct X : public X {};", + traverse(TK_AsIs, cxxRecordDecl(isDerivedFrom( + recordDecl(hasName("Some"))))))); EXPECT_TRUE(matches( "struct A {};" "template struct X;" "template struct X : public X {};" "template<> struct X<0> : public A {};" "struct B : public X<42> {};", - cxxRecordDecl(hasName("B"), isDerivedFrom(recordDecl(hasName("A")))))); + traverse(TK_AsIs, cxxRecordDecl(hasName("B"), isDerivedFrom(recordDecl( + hasName("A"))))))); EXPECT_TRUE(notMatches( "struct A {};" "template struct X;" "template struct X : public X {};" "template<> struct X<0> : public A {};" "struct B : public X<42> {};", - cxxRecordDecl(hasName("B"), - isDirectlyDerivedFrom(recordDecl(hasName("A")))))); + traverse(TK_AsIs, + cxxRecordDecl(hasName("B"), isDirectlyDerivedFrom( + recordDecl(hasName("A"))))))); // FIXME: Once we have better matchers for template type matching, // get rid of the Variable(...) matching and match the right template @@ -662,19 +666,22 @@ "template <> class Z : public Z {};" "template class Z : public Z, public Z {};" "void f() { Z z_float; Z z_double; Z z_char; }"; - EXPECT_TRUE(matches( - RecursiveTemplateOneParameter, - varDecl(hasName("z_float"), - hasInitializer(hasType(cxxRecordDecl(isDerivedFrom("Base1"))))))); - EXPECT_TRUE(notMatches( - RecursiveTemplateOneParameter, - varDecl(hasName("z_float"), - hasInitializer(hasType(cxxRecordDecl(isDerivedFrom("Base2"))))))); EXPECT_TRUE( matches(RecursiveTemplateOneParameter, - varDecl(hasName("z_char"), - hasInitializer(hasType(cxxRecordDecl( - isDerivedFrom("Base1"), isDerivedFrom("Base2"))))))); + traverse(TK_AsIs, varDecl(hasName("z_float"), + hasInitializer(hasType(cxxRecordDecl( + isDerivedFrom("Base1")))))))); + EXPECT_TRUE( + notMatches(RecursiveTemplateOneParameter, + traverse(TK_AsIs, varDecl(hasName("z_float"), + hasInitializer(hasType(cxxRecordDecl( + isDerivedFrom("Base2")))))))); + EXPECT_TRUE( + matches(RecursiveTemplateOneParameter, + traverse(TK_AsIs, varDecl(hasName("z_char"), + hasInitializer(hasType(cxxRecordDecl( + isDerivedFrom("Base1"), + isDerivedFrom("Base2")))))))); const char *RecursiveTemplateTwoParameters = "class Base1 {}; class Base2 {};" @@ -687,6 +694,8 @@ " public Z, public Z {};" "void f() { Z z_float; Z z_double; " " Z z_char; }"; + + // TODO: No change? EXPECT_TRUE(matches( RecursiveTemplateTwoParameters, varDecl(hasName("z_float"), @@ -842,7 +851,8 @@ return; } - const auto IsLambda = cxxMethodDecl(ofClass(cxxRecordDecl(isLambda()))); + const auto IsLambda = + traverse(TK_AsIs, cxxMethodDecl(ofClass(cxxRecordDecl(isLambda())))); EXPECT_TRUE(matches("auto x = []{};", IsLambda)); EXPECT_TRUE(notMatches("struct S { void operator()() const; };", IsLambda)); } @@ -1231,10 +1241,12 @@ matches("class X {}; void y(X y) { const X &x = y; }", ReferenceClassX)); // The match here is on the implicit copy constructor code for // class X, not on code 'X x = y'. - EXPECT_TRUE(matches("class X {}; void y(X y) { X x = y; }", ReferenceClassX)); - EXPECT_TRUE(notMatches("class X {}; extern X x;", ReferenceClassX)); - EXPECT_TRUE( - notMatches("class X {}; void y(X *y) { X *&x = y; }", ReferenceClassX)); + EXPECT_TRUE(matches("class X {}; void y(X y) { X x = y; }", + traverse(TK_AsIs, ReferenceClassX))); + EXPECT_TRUE(notMatches("class X {}; extern X x;", + traverse(TK_AsIs, ReferenceClassX))); + EXPECT_TRUE(notMatches("class X {}; void y(X *y) { X *&x = y; }", + traverse(TK_AsIs, ReferenceClassX))); } TEST_P(ASTMatchersTest, HasLocalQualifiers) { @@ -1405,18 +1417,19 @@ return; } - EXPECT_TRUE( - matches("template struct C {}; C c;", - classTemplateSpecializationDecl(templateArgumentCountIs(1)))); - EXPECT_TRUE( - notMatches("template struct C {}; C c;", - classTemplateSpecializationDecl(templateArgumentCountIs(2)))); + EXPECT_TRUE(matches("template struct C {}; C c;", + traverse(TK_AsIs, classTemplateSpecializationDecl( + templateArgumentCountIs(1))))); + EXPECT_TRUE(notMatches("template struct C {}; C c;", + traverse(TK_AsIs, classTemplateSpecializationDecl( + templateArgumentCountIs(2))))); EXPECT_TRUE(matches("template struct C {}; C c;", - templateSpecializationType(templateArgumentCountIs(1)))); - EXPECT_TRUE( - notMatches("template struct C {}; C c;", - templateSpecializationType(templateArgumentCountIs(2)))); + traverse(TK_AsIs, templateSpecializationType( + templateArgumentCountIs(1))))); + EXPECT_TRUE(notMatches("template struct C {}; C c;", + traverse(TK_AsIs, templateSpecializationType( + templateArgumentCountIs(2))))); } TEST_P(ASTMatchersTest, IsIntegral) { @@ -1424,12 +1437,14 @@ return; } - EXPECT_TRUE(matches( - "template struct C {}; C<42> c;", - classTemplateSpecializationDecl(hasAnyTemplateArgument(isIntegral())))); - EXPECT_TRUE(notMatches("template struct C {}; C c;", - classTemplateSpecializationDecl(hasAnyTemplateArgument( - templateArgument(isIntegral()))))); + EXPECT_TRUE( + matches("template struct C {}; C<42> c;", + traverse(TK_AsIs, classTemplateSpecializationDecl( + hasAnyTemplateArgument(isIntegral()))))); + EXPECT_TRUE(notMatches( + "template struct C {}; C c;", + traverse(TK_AsIs, classTemplateSpecializationDecl(hasAnyTemplateArgument( + templateArgument(isIntegral())))))); } TEST_P(ASTMatchersTest, EqualsIntegralValue) { @@ -1437,18 +1452,22 @@ return; } - EXPECT_TRUE(matches("template struct C {}; C<42> c;", - classTemplateSpecializationDecl( - hasAnyTemplateArgument(equalsIntegralValue("42"))))); - EXPECT_TRUE(matches("template struct C {}; C<-42> c;", - classTemplateSpecializationDecl( - hasAnyTemplateArgument(equalsIntegralValue("-42"))))); - EXPECT_TRUE(matches("template struct C {}; C<-0042> c;", - classTemplateSpecializationDecl( - hasAnyTemplateArgument(equalsIntegralValue("-34"))))); - EXPECT_TRUE(notMatches("template struct C {}; C<42> c;", - classTemplateSpecializationDecl(hasAnyTemplateArgument( - equalsIntegralValue("0042"))))); + EXPECT_TRUE(matches( + "template struct C {}; C<42> c;", + traverse(TK_AsIs, classTemplateSpecializationDecl(hasAnyTemplateArgument( + equalsIntegralValue("42")))))); + EXPECT_TRUE(matches( + "template struct C {}; C<-42> c;", + traverse(TK_AsIs, classTemplateSpecializationDecl(hasAnyTemplateArgument( + equalsIntegralValue("-42")))))); + EXPECT_TRUE(matches( + "template struct C {}; C<-0042> c;", + traverse(TK_AsIs, classTemplateSpecializationDecl(hasAnyTemplateArgument( + equalsIntegralValue("-34")))))); + EXPECT_TRUE(notMatches( + "template struct C {}; C<42> c;", + traverse(TK_AsIs, classTemplateSpecializationDecl(hasAnyTemplateArgument( + equalsIntegralValue("0042")))))); } TEST_P(ASTMatchersTest, AccessSpecDecl) { @@ -1757,15 +1776,18 @@ // This one doesn't match because the constructor is not added by the // compiler (it is not needed). - EXPECT_TRUE(notMatches("class Foo { };", cxxConstructorDecl(isImplicit()))); + EXPECT_TRUE(notMatches("class Foo { };", + traverse(TK_AsIs, cxxConstructorDecl(isImplicit())))); // The compiler added the implicit default constructor. EXPECT_TRUE(matches("class Foo { }; Foo* f = new Foo();", - cxxConstructorDecl(isImplicit()))); - EXPECT_TRUE(matches("class Foo { Foo(){} };", - cxxConstructorDecl(unless(isImplicit())))); + traverse(TK_AsIs, cxxConstructorDecl(isImplicit())))); + EXPECT_TRUE( + matches("class Foo { Foo(){} };", + traverse(TK_AsIs, cxxConstructorDecl(unless(isImplicit()))))); // The compiler added an implicit assignment operator. - EXPECT_TRUE(matches("struct A { int x; } a = {0}, b = a; void f() { a = b; }", - cxxMethodDecl(isImplicit(), hasName("operator=")))); + EXPECT_TRUE(matches( + "struct A { int x; } a = {0}, b = a; void f() { a = b; }", + traverse(TK_AsIs, cxxMethodDecl(isImplicit(), hasName("operator="))))); } TEST_P(ASTMatchersTest, IsExplicit_CXXConstructorDecl) { @@ -2508,13 +2530,14 @@ EXPECT_TRUE( matches("template class X {}; class A {}; X x;", - cxxRecordDecl(hasName("::X"), isTemplateInstantiation()))); + traverse(TK_AsIs, cxxRecordDecl(hasName("::X"), + isTemplateInstantiation())))); EXPECT_TRUE(matches( "template class X { T t; }; class A {}; X x;", - cxxRecordDecl( - isTemplateInstantiation(), - hasDescendant(fieldDecl(hasType(recordDecl(hasName("A")))))))); + traverse(TK_AsIs, cxxRecordDecl(isTemplateInstantiation(), + hasDescendant(fieldDecl(hasType( + recordDecl(hasName("A"))))))))); } TEST_P(ASTMatchersTest, @@ -2525,8 +2548,9 @@ EXPECT_TRUE(matches( "template void f(T t) {} class A {}; void g() { f(A()); }", - functionDecl(hasParameter(0, hasType(recordDecl(hasName("A")))), - isTemplateInstantiation()))); + traverse(TK_AsIs, + functionDecl(hasParameter(0, hasType(recordDecl(hasName("A")))), + isTemplateInstantiation())))); } TEST_P(ASTMatchersTest, @@ -2535,19 +2559,21 @@ return; } - EXPECT_TRUE(matches("template class X { T t; }; class A {};" - "template class X;", - cxxRecordDecl(isTemplateInstantiation(), - hasDescendant(fieldDecl( - hasType(recordDecl(hasName("A")))))))); + EXPECT_TRUE(matches( + "template class X { T t; }; class A {};" + "template class X;", + traverse(TK_AsIs, cxxRecordDecl(isTemplateInstantiation(), + hasDescendant(fieldDecl(hasType( + recordDecl(hasName("A"))))))))); // Make sure that we match the instantiation instead of the template // definition by checking whether the member function is present. - EXPECT_TRUE( - matches("template class X { void f() { T t; } };" - "extern template class X;", - cxxRecordDecl(isTemplateInstantiation(), - unless(hasDescendant(varDecl(hasName("t"))))))); + EXPECT_TRUE(matches( + "template class X { void f() { T t; } };" + "extern template class X;", + traverse(TK_AsIs, + cxxRecordDecl(isTemplateInstantiation(), + unless(hasDescendant(varDecl(hasName("t")))))))); } TEST_P( @@ -2560,7 +2586,8 @@ EXPECT_TRUE( matches("template class X {};" "template class X {}; class A {}; X x;", - cxxRecordDecl(hasName("::X"), isTemplateInstantiation()))); + traverse(TK_AsIs, cxxRecordDecl(hasName("::X"), + isTemplateInstantiation())))); } TEST_P( @@ -2576,7 +2603,8 @@ " template class Y { U u; };" " Y y;" "};", - cxxRecordDecl(hasName("::X::Y"), isTemplateInstantiation()))); + traverse(TK_AsIs, cxxRecordDecl(hasName("::X::Y"), + isTemplateInstantiation())))); } TEST_P( @@ -2595,7 +2623,8 @@ " template class Y { U u; };" " Y y;" "}; X x;", - cxxRecordDecl(hasName("::X::Y"), unless(isTemplateInstantiation())))); + traverse(TK_AsIs, cxxRecordDecl(hasName("::X::Y"), + unless(isTemplateInstantiation()))))); } TEST_P( @@ -2627,7 +2656,7 @@ EXPECT_TRUE( matches("template class A { T i; }; class Y { A a; };", - cxxRecordDecl(isInstantiated()))); + traverse(TK_AsIs, cxxRecordDecl(isInstantiated())))); } TEST_P(ASTMatchersTest, IsInstantiated_NotMatchesDefinition) { @@ -2644,9 +2673,10 @@ return; } - EXPECT_TRUE(matches("template struct A { A() { T i; } };" - "class Y { A a; }; Y y;", - declStmt(isInTemplateInstantiation()))); + EXPECT_TRUE( + matches("template struct A { A() { T i; } };" + "class Y { A a; }; Y y;", + traverse(TK_AsIs, declStmt(isInTemplateInstantiation())))); } TEST_P(ASTMatchersTest, IsInTemplateInstantiation_NotMatchesDefinitionStmt) { @@ -2665,7 +2695,7 @@ EXPECT_TRUE( matches("template void A(T t) { T i; } void x() { A(0); }", - functionDecl(isInstantiated()))); + traverse(TK_AsIs, functionDecl(isInstantiated())))); } TEST_P(ASTMatchersTest, IsInstantiated_NotMatchesFunctionDefinition) { @@ -2685,7 +2715,7 @@ EXPECT_TRUE( matches("template void A(T t) { T i; } void x() { A(0); }", - declStmt(isInTemplateInstantiation()))); + traverse(TK_AsIs, declStmt(isInTemplateInstantiation())))); } TEST_P(ASTMatchersTest, @@ -3429,10 +3459,10 @@ EXPECT_TRUE(matches( "auto lambda2 = [](double x, double y) -> double {return x + y;};", - functionDecl(hasTrailingReturn()))); + traverse(TK_AsIs, functionDecl(hasTrailingReturn())))); EXPECT_TRUE( notMatches("auto lambda2 = [](double x, double y) {return x + y;};", - functionDecl(hasTrailingReturn()))); + traverse(TK_AsIs, functionDecl(hasTrailingReturn())))); } TEST_P(ASTMatchersTest, IsAssignmentOperator) { diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -711,11 +711,11 @@ } EXPECT_TRUE(matches("template struct A {};" "template<> struct A {};", - classTemplateSpecializationDecl())); + traverse(TK_AsIs, classTemplateSpecializationDecl()))); EXPECT_TRUE(matches("template struct A {}; A a;", - classTemplateSpecializationDecl())); + traverse(TK_AsIs, classTemplateSpecializationDecl()))); EXPECT_TRUE(notMatches("template struct A {};", - classTemplateSpecializationDecl())); + traverse(TK_AsIs, classTemplateSpecializationDecl()))); } TEST_P(ASTMatchersTest, DeclaratorDecl) { @@ -1021,14 +1021,16 @@ "void foo() { struct point { double x; double y; };" " struct point ptarray[10] = " " { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; }", - initListExpr( - has(cxxConstructExpr(requiresZeroInitialization())), - has(initListExpr( - hasType(asString("struct point")), has(floatLiteral(equals(1.0))), - has(implicitValueInitExpr(hasType(asString("double")))))), - has(initListExpr(hasType(asString("struct point")), - has(floatLiteral(equals(2.0))), - has(floatLiteral(equals(1.0)))))))); + traverse( + TK_AsIs, + initListExpr(has(cxxConstructExpr(requiresZeroInitialization())), + has(initListExpr(hasType(asString("struct point")), + has(floatLiteral(equals(1.0))), + has(implicitValueInitExpr( + hasType(asString("double")))))), + has(initListExpr(hasType(asString("struct point")), + has(floatLiteral(equals(2.0))), + has(floatLiteral(equals(1.0))))))))); } TEST_P(ASTMatchersTest, ParenListExpr) { @@ -1189,19 +1191,20 @@ TEST_P(ASTMatchersTest, CastExpr_DoesNotMatchNonCasts) { if (GetParam().Language == Lang_C89 || GetParam().Language == Lang_C99) { // This does have a cast in C - EXPECT_TRUE(matches("char c = '0';", implicitCastExpr())); + EXPECT_TRUE( + matches("char c = '0';", traverse(TK_AsIs, implicitCastExpr()))); } else { - EXPECT_TRUE(notMatches("char c = '0';", castExpr())); + EXPECT_TRUE(notMatches("char c = '0';", traverse(TK_AsIs, castExpr()))); } - EXPECT_TRUE(notMatches("int i = (0);", castExpr())); - EXPECT_TRUE(notMatches("int i = 0;", castExpr())); + EXPECT_TRUE(notMatches("int i = (0);", traverse(TK_AsIs, castExpr()))); + EXPECT_TRUE(notMatches("int i = 0;", traverse(TK_AsIs, castExpr()))); } TEST_P(ASTMatchersTest, CastExpr_DoesNotMatchNonCasts_CXX) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(notMatches("char c, &q = c;", castExpr())); + EXPECT_TRUE(notMatches("char c, &q = c;", traverse(TK_AsIs, castExpr()))); } TEST_P(ASTMatchersTest, CXXReinterpretCastExpr) { @@ -1233,7 +1236,7 @@ } StringRef foo_class = "class Foo { public: Foo(const char*); };"; EXPECT_TRUE(matches(foo_class + "void r() { Foo f = Foo(\"hello world\"); }", - cxxFunctionalCastExpr())); + traverse(TK_AsIs, cxxFunctionalCastExpr()))); } TEST_P(ASTMatchersTest, CXXFunctionalCastExpr_DoesNotMatchOtherCasts) { @@ -1243,9 +1246,9 @@ StringRef FooClass = "class Foo { public: Foo(const char*); };"; EXPECT_TRUE( notMatches(FooClass + "void r() { Foo f = (Foo) \"hello world\"; }", - cxxFunctionalCastExpr())); + traverse(TK_AsIs, cxxFunctionalCastExpr()))); EXPECT_TRUE(notMatches(FooClass + "void r() { Foo f = \"hello world\"; }", - cxxFunctionalCastExpr())); + traverse(TK_AsIs, cxxFunctionalCastExpr()))); } TEST_P(ASTMatchersTest, CXXDynamicCastExpr) { @@ -1508,7 +1511,8 @@ } TEST_P(ASTMatchersTest, QualType) { - EXPECT_TRUE(matches("struct S {};", qualType().bind("loc"))); + EXPECT_TRUE( + matches("struct S {};", traverse(TK_AsIs, qualType().bind("loc")))); } TEST_P(ASTMatchersTest, ConstantArrayType) { @@ -1569,7 +1573,7 @@ } EXPECT_TRUE(matches("auto i = 2;", autoType())); EXPECT_TRUE(matches("int v[] = { 2, 3 }; void f() { for (int i : v) {} }", - autoType())); + traverse(TK_AsIs, autoType()))); EXPECT_TRUE(matches("auto i = 2;", varDecl(hasType(isInteger())))); EXPECT_TRUE(matches("struct X{}; auto x = X{};", @@ -1843,10 +1847,12 @@ " return 1 + T();" "}" "int i = F();"; - EXPECT_FALSE(matches(code, binaryOperator(hasLHS( - expr(hasType(substTemplateTypeParmType())))))); - EXPECT_TRUE(matches(code, binaryOperator(hasRHS( - expr(hasType(substTemplateTypeParmType())))))); + EXPECT_FALSE( + matches(code, traverse(TK_AsIs, binaryOperator(hasLHS(expr(hasType( + substTemplateTypeParmType()))))))); + EXPECT_TRUE( + matches(code, traverse(TK_AsIs, binaryOperator(hasRHS(expr(hasType( + substTemplateTypeParmType()))))))); } TEST_P(ASTMatchersTest, NestedNameSpecifier) { diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -26,13 +26,14 @@ } TEST(DeclarationMatcher, ClassDerivedFromDependentTemplateSpecialization) { - EXPECT_TRUE(matches( - "template struct A {" - " template struct F {};" - "};" - "template struct B : A::template F {};" - "B b;", - cxxRecordDecl(hasName("B"), isDerivedFrom(recordDecl())))); + EXPECT_TRUE( + matches("template struct A {" + " template struct F {};" + "};" + "template struct B : A::template F {};" + "B b;", + traverse(TK_AsIs, cxxRecordDecl(hasName("B"), + isDerivedFrom(recordDecl()))))); } TEST(DeclarationMatcher, hasDeclContext) { @@ -262,9 +263,9 @@ } TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) { - EXPECT_TRUE( - matches("int *A = new int();", - cxxNewExpr(hasDeclaration(functionDecl(parameterCountIs(1)))))); + EXPECT_TRUE(matches("int *A = new int();", + traverse(TK_AsIs, cxxNewExpr(hasDeclaration(functionDecl( + parameterCountIs(1))))))); } TEST(HasDeclaration, HasDeclarationOfTypeAlias) { @@ -981,60 +982,63 @@ TEST(Matcher, MatchesTypeTemplateArgument) { EXPECT_TRUE(matches( - "template struct B {};" + "template struct B {};" "B b;", - classTemplateSpecializationDecl(hasAnyTemplateArgument(refersToType( - asString("int")))))); + traverse(TK_AsIs, classTemplateSpecializationDecl(hasAnyTemplateArgument( + refersToType(asString("int"))))))); } TEST(Matcher, MatchesTemplateTemplateArgument) { - EXPECT_TRUE(matches("template