From db1ddbd636f629a2f61f6c7c2f49ead07bb181c1 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 21 Apr 2016 13:51:07 +0000 Subject: [PATCH] Clarify memory ownership semantics; NFC. Patch by Clement Courbet git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266986 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/ASTMatchers/ASTMatchersTest.cpp | 170 +++++++++++----------- unittests/ASTMatchers/ASTMatchersTest.h | 19 ++- 2 files changed, 96 insertions(+), 93 deletions(-) diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index 7bb9550cd9..332438ede1 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -830,7 +830,7 @@ TEST(HasDescendant, MatchesDescendantTypes) { "void f() { int a; float c; int d; int e; }", functionDecl(forEachDescendant( varDecl(hasDescendant(isInteger())).bind("x"))), - new VerifyIdIsBoundTo("x", 3))); + llvm::make_unique>("x", 3))); } TEST(HasDescendant, MatchesDescendantsOfTypes) { @@ -845,7 +845,7 @@ TEST(HasDescendant, MatchesDescendantsOfTypes) { EXPECT_TRUE(matchAndVerifyResultTrue( "void f() { int*** i; }", qualType(asString("int ***"), forEachDescendant(pointerType().bind("x"))), - new VerifyIdIsBoundTo("x", 2))); + llvm::make_unique>("x", 2))); } TEST(Has, MatchesChildrenOfTypes) { @@ -856,7 +856,7 @@ TEST(Has, MatchesChildrenOfTypes) { EXPECT_TRUE(matchAndVerifyResultTrue( "int (*f)(float, int);", qualType(functionType(), forEach(qualType(isInteger()).bind("x"))), - new VerifyIdIsBoundTo("x", 2))); + llvm::make_unique>("x", 2))); } TEST(Has, MatchesChildTypes) { @@ -989,24 +989,24 @@ TEST(Matcher, BindMatchedNodes) { DeclarationMatcher ClassX = has(recordDecl(hasName("::X")).bind("x")); EXPECT_TRUE(matchAndVerifyResultTrue("class X {};", - ClassX, new VerifyIdIsBoundTo("x"))); + ClassX, llvm::make_unique>("x"))); EXPECT_TRUE(matchAndVerifyResultFalse("class X {};", - ClassX, new VerifyIdIsBoundTo("other-id"))); + ClassX, llvm::make_unique>("other-id"))); TypeMatcher TypeAHasClassB = hasDeclaration( recordDecl(hasName("A"), has(recordDecl(hasName("B")).bind("b")))); EXPECT_TRUE(matchAndVerifyResultTrue("class A { public: A *a; class B {}; };", TypeAHasClassB, - new VerifyIdIsBoundTo("b"))); + llvm::make_unique>("b"))); StatementMatcher MethodX = callExpr(callee(cxxMethodDecl(hasName("x")))).bind("x"); EXPECT_TRUE(matchAndVerifyResultTrue("class A { void x() { x(); } };", MethodX, - new VerifyIdIsBoundTo("x"))); + llvm::make_unique>("x"))); } TEST(Matcher, BindTheSameNameInAlternatives) { @@ -1023,7 +1023,7 @@ TEST(Matcher, BindTheSameNameInAlternatives) { // The second branch binds x to f() and succeeds. "int f() { return 0 + f(); }", matcher, - new VerifyIdIsBoundTo("x"))); + llvm::make_unique>("x"))); } TEST(Matcher, BindsIDForMemoizedResults) { @@ -1035,7 +1035,7 @@ TEST(Matcher, BindsIDForMemoizedResults) { DeclarationMatcher(anyOf( recordDecl(hasName("A"), hasDescendant(ClassX)), recordDecl(hasName("B"), hasDescendant(ClassX)))), - new VerifyIdIsBoundTo("x", 2))); + llvm::make_unique>("x", 2))); } TEST(HasDeclaration, HasDeclarationOfEnumType) { @@ -1313,7 +1313,7 @@ TEST(Matcher, NestedOverloadedOperatorCalls) { "Y& operator&&(Y& x, Y& y) { return x; }; " "Y a; Y b; Y c; Y d = a && b && c;", cxxOperatorCallExpr(hasOverloadedOperatorName("&&")).bind("x"), - new VerifyIdIsBoundTo("x", 2))); + llvm::make_unique>("x", 2))); EXPECT_TRUE(matches("class Y { }; " "Y& operator&&(Y& x, Y& y) { return x; }; " "Y a; Y b; Y c; Y d = a && b && c;", @@ -1694,7 +1694,7 @@ TEST(ForEachArgumentWithParam, MatchesCXXMemberCallExpr) { " int y = 1;" " S1[y];" "}", - CallExpr, new VerifyIdIsBoundTo("param", 1))); + CallExpr, llvm::make_unique>("param", 1))); StatementMatcher CallExpr2 = callExpr(forEachArgumentWithParam(ArgumentY, IntParam)); @@ -1706,7 +1706,7 @@ TEST(ForEachArgumentWithParam, MatchesCXXMemberCallExpr) { " int y = 1;" " S::g(y);" "}", - CallExpr2, new VerifyIdIsBoundTo("param", 1))); + CallExpr2, llvm::make_unique>("param", 1))); } TEST(ForEachArgumentWithParam, MatchesCallExpr) { @@ -1718,17 +1718,19 @@ TEST(ForEachArgumentWithParam, MatchesCallExpr) { EXPECT_TRUE( matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr, - new VerifyIdIsBoundTo("param"))); + llvm::make_unique>( + "param"))); EXPECT_TRUE( matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr, - new VerifyIdIsBoundTo("arg"))); + llvm::make_unique>( + "arg"))); EXPECT_TRUE(matchAndVerifyResultTrue( "void f(int i, int j) { int y; f(y, y); }", CallExpr, - new VerifyIdIsBoundTo("param", 2))); + llvm::make_unique>("param", 2))); EXPECT_TRUE(matchAndVerifyResultTrue( "void f(int i, int j) { int y; f(y, y); }", CallExpr, - new VerifyIdIsBoundTo("arg", 2))); + llvm::make_unique>("arg", 2))); } TEST(ForEachArgumentWithParam, MatchesConstructExpr) { @@ -1744,7 +1746,8 @@ TEST(ForEachArgumentWithParam, MatchesConstructExpr) { "};" "int y = 0;" "C Obj(y);", - ConstructExpr, new VerifyIdIsBoundTo("param"))); + ConstructExpr, + llvm::make_unique>("param"))); } TEST(ForEachArgumentWithParam, HandlesBoundNodesForNonMatches) { @@ -1761,7 +1764,7 @@ TEST(ForEachArgumentWithParam, HandlesBoundNodesForNonMatches) { forEachDescendant(varDecl().bind("v")), forEachDescendant(callExpr(forEachArgumentWithParam( declRefExpr(to(decl(equalsBoundNode("v")))), parmVarDecl())))), - new VerifyIdIsBoundTo("v", 4))); + llvm::make_unique>("v", 4))); } TEST(Matcher, ArgumentCount) { @@ -3146,13 +3149,13 @@ TEST(AstMatcherPMacro, Works) { DeclarationMatcher HasClassB = just(has(recordDecl(hasName("B")).bind("b"))); EXPECT_TRUE(matchAndVerifyResultTrue("class A { class B {}; };", - HasClassB, new VerifyIdIsBoundTo("b"))); + HasClassB, llvm::make_unique>("b"))); EXPECT_TRUE(matchAndVerifyResultFalse("class A { class B {}; };", - HasClassB, new VerifyIdIsBoundTo("a"))); + HasClassB, llvm::make_unique>("a"))); EXPECT_TRUE(matchAndVerifyResultFalse("class A { class C {}; };", - HasClassB, new VerifyIdIsBoundTo("b"))); + HasClassB, llvm::make_unique>("b"))); } AST_POLYMORPHIC_MATCHER_P(polymorphicHas, @@ -3169,13 +3172,13 @@ TEST(AstPolymorphicMatcherPMacro, Works) { polymorphicHas(recordDecl(hasName("B")).bind("b")); EXPECT_TRUE(matchAndVerifyResultTrue("class A { class B {}; };", - HasClassB, new VerifyIdIsBoundTo("b"))); + HasClassB, llvm::make_unique>("b"))); EXPECT_TRUE(matchAndVerifyResultFalse("class A { class B {}; };", - HasClassB, new VerifyIdIsBoundTo("a"))); + HasClassB, llvm::make_unique>("a"))); EXPECT_TRUE(matchAndVerifyResultFalse("class A { class C {}; };", - HasClassB, new VerifyIdIsBoundTo("b"))); + HasClassB, llvm::make_unique>("b"))); StatementMatcher StatementHasClassB = polymorphicHas(recordDecl(hasName("B"))); @@ -3914,7 +3917,7 @@ TEST(SwitchCase, MatchesEachCase) { EXPECT_TRUE(matchAndVerifyResultTrue( "void x() { switch (42) { case 1: case 2: case 3: default:; } }", switchStmt(forEachSwitchCase(caseStmt().bind("x"))), - new VerifyIdIsBoundTo("x", 3))); + llvm::make_unique>("x", 3))); } TEST(ForEachConstructorInitializer, MatchesInitializers) { @@ -3968,13 +3971,13 @@ TEST(HasConditionVariableStatement, MatchesConditionVariables) { TEST(ForEach, BindsOneNode) { EXPECT_TRUE(matchAndVerifyResultTrue("class C { int x; };", recordDecl(hasName("C"), forEach(fieldDecl(hasName("x")).bind("x"))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); } TEST(ForEach, BindsMultipleNodes) { EXPECT_TRUE(matchAndVerifyResultTrue("class C { int x; int y; int z; };", recordDecl(hasName("C"), forEach(fieldDecl().bind("f"))), - new VerifyIdIsBoundTo("f", 3))); + llvm::make_unique>("f", 3))); } TEST(ForEach, BindsRecursiveCombinations) { @@ -3982,14 +3985,14 @@ TEST(ForEach, BindsRecursiveCombinations) { "class C { class D { int x; int y; }; class E { int y; int z; }; };", recordDecl(hasName("C"), forEach(recordDecl(forEach(fieldDecl().bind("f"))))), - new VerifyIdIsBoundTo("f", 4))); + llvm::make_unique>("f", 4))); } TEST(ForEachDescendant, BindsOneNode) { EXPECT_TRUE(matchAndVerifyResultTrue("class C { class D { int x; }; };", recordDecl(hasName("C"), forEachDescendant(fieldDecl(hasName("x")).bind("x"))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); } TEST(ForEachDescendant, NestedForEachDescendant) { @@ -3998,7 +4001,7 @@ TEST(ForEachDescendant, NestedForEachDescendant) { EXPECT_TRUE(matchAndVerifyResultTrue( "class A { class B { class C {}; }; };", recordDecl(hasName("A"), anyOf(m, forEachDescendant(m))), - new VerifyIdIsBoundTo("x", "C"))); + llvm::make_unique>("x", "C"))); // Check that a partial match of 'm' that binds 'x' in the // first part of anyOf(m, anything()) will not overwrite the @@ -4006,7 +4009,7 @@ TEST(ForEachDescendant, NestedForEachDescendant) { EXPECT_TRUE(matchAndVerifyResultTrue( "class A { class B { class C {}; }; };", recordDecl(hasName("A"), allOf(hasDescendant(m), anyOf(m, anything()))), - new VerifyIdIsBoundTo("x", "C"))); + llvm::make_unique>("x", "C"))); } TEST(ForEachDescendant, BindsMultipleNodes) { @@ -4014,7 +4017,7 @@ TEST(ForEachDescendant, BindsMultipleNodes) { "class C { class D { int x; int y; }; " " class E { class F { int y; int z; }; }; };", recordDecl(hasName("C"), forEachDescendant(fieldDecl().bind("f"))), - new VerifyIdIsBoundTo("f", 4))); + llvm::make_unique>("f", 4))); } TEST(ForEachDescendant, BindsRecursiveCombinations) { @@ -4023,7 +4026,7 @@ TEST(ForEachDescendant, BindsRecursiveCombinations) { " class E { class F { class G { int y; int z; }; }; }; }; };", recordDecl(hasName("C"), forEachDescendant(recordDecl( forEachDescendant(fieldDecl().bind("f"))))), - new VerifyIdIsBoundTo("f", 8))); + llvm::make_unique>("f", 8))); } TEST(ForEachDescendant, BindsCombinations) { @@ -4032,13 +4035,13 @@ TEST(ForEachDescendant, BindsCombinations) { "(true) {} }", compoundStmt(forEachDescendant(ifStmt().bind("if")), forEachDescendant(whileStmt().bind("while"))), - new VerifyIdIsBoundTo("if", 6))); + llvm::make_unique>("if", 6))); } TEST(Has, DoesNotDeleteBindings) { EXPECT_TRUE(matchAndVerifyResultTrue( "class X { int a; };", recordDecl(decl().bind("x"), has(fieldDecl())), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); } TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) { @@ -4066,100 +4069,100 @@ TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) { recordDecl( recordDecl().bind("x"), hasName("::X"), anyOf(forEachDescendant(recordDecl(hasName("Y"))), anything())), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class X {};", recordDecl(recordDecl().bind("x"), hasName("::X"), anyOf(unless(anything()), anything())), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "template class X {}; X x;", classTemplateSpecializationDecl( decl().bind("x"), hasAnyTemplateArgument(refersToType(asString("int")))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class X { void f(); void g(); };", cxxRecordDecl(decl().bind("x"), hasMethod(hasName("g"))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class X { X() : a(1), b(2) {} double a; int b; };", recordDecl(decl().bind("x"), has(cxxConstructorDecl( hasAnyConstructorInitializer(forField(hasName("b")))))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "void x(int, int) { x(0, 42); }", callExpr(expr().bind("x"), hasAnyArgument(integerLiteral(equals(42)))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "void x(int, int y) {}", functionDecl(decl().bind("x"), hasAnyParameter(hasName("y"))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "void x() { return; if (true) {} }", functionDecl(decl().bind("x"), has(compoundStmt(hasAnySubstatement(ifStmt())))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "namespace X { void b(int); void b(); }" "using X::b;", usingDecl(decl().bind("x"), hasAnyUsingShadowDecl(hasTargetDecl( functionDecl(parameterCountIs(1))))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A{}; class B{}; class C : B, A {};", cxxRecordDecl(decl().bind("x"), isDerivedFrom("::A")), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A{}; typedef A B; typedef A C; typedef A D;" "class E : A {};", cxxRecordDecl(decl().bind("x"), isDerivedFrom("C")), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A { class B { void f() {} }; };", functionDecl(decl().bind("x"), hasAncestor(recordDecl(hasName("::A")))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "template struct A { struct B {" " void f() { if(true) {} }" "}; };" "void t() { A::B b; b.f(); }", ifStmt(stmt().bind("x"), hasAncestor(recordDecl(hasName("::A")))), - new VerifyIdIsBoundTo("x", 2))); + llvm::make_unique>("x", 2))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A {};", recordDecl(hasName("::A"), decl().bind("x"), unless(hasName("fooble"))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A { A() : s(), i(42) {} const char *s; int i; };", cxxConstructorDecl(hasName("::A::A"), decl().bind("x"), forEachConstructorInitializer(forField(hasName("i")))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); } TEST(ForEachDescendant, BindsCorrectNodes) { EXPECT_TRUE(matchAndVerifyResultTrue( "class C { void f(); int i; };", recordDecl(hasName("C"), forEachDescendant(decl().bind("decl"))), - new VerifyIdIsBoundTo("decl", 1))); + llvm::make_unique>("decl", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class C { void f() {} int i; };", recordDecl(hasName("C"), forEachDescendant(decl().bind("decl"))), - new VerifyIdIsBoundTo("decl", 1))); + llvm::make_unique>("decl", 1))); } TEST(FindAll, BindsNodeOnMatch) { EXPECT_TRUE(matchAndVerifyResultTrue( "class A {};", recordDecl(hasName("::A"), findAll(recordDecl(hasName("::A")).bind("v"))), - new VerifyIdIsBoundTo("v", 1))); + llvm::make_unique>("v", 1))); } TEST(FindAll, BindsDescendantNodeOnMatch) { EXPECT_TRUE(matchAndVerifyResultTrue( "class A { int a; int b; };", recordDecl(hasName("::A"), findAll(fieldDecl().bind("v"))), - new VerifyIdIsBoundTo("v", 2))); + llvm::make_unique>("v", 2))); } TEST(FindAll, BindsNodeAndDescendantNodesOnOneMatch) { @@ -4168,12 +4171,12 @@ TEST(FindAll, BindsNodeAndDescendantNodesOnOneMatch) { recordDecl(hasName("::A"), findAll(decl(anyOf(recordDecl(hasName("::A")).bind("v"), fieldDecl().bind("v"))))), - new VerifyIdIsBoundTo("v", 3))); + llvm::make_unique>("v", 3))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A { class B {}; class C {}; };", recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("v"))), - new VerifyIdIsBoundTo("v", 3))); + llvm::make_unique>("v", 3))); } TEST(EachOf, TriggersForEachMatch) { @@ -4181,7 +4184,7 @@ TEST(EachOf, TriggersForEachMatch) { "class A { int a; int b; };", recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), has(fieldDecl(hasName("b")).bind("v")))), - new VerifyIdIsBoundTo("v", 2))); + llvm::make_unique>("v", 2))); } TEST(EachOf, BehavesLikeAnyOfUnlessBothMatch) { @@ -4189,12 +4192,12 @@ TEST(EachOf, BehavesLikeAnyOfUnlessBothMatch) { "class A { int a; int c; };", recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), has(fieldDecl(hasName("b")).bind("v")))), - new VerifyIdIsBoundTo("v", 1))); + llvm::make_unique>("v", 1))); EXPECT_TRUE(matchAndVerifyResultTrue( "class A { int c; int b; };", recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), has(fieldDecl(hasName("b")).bind("v")))), - new VerifyIdIsBoundTo("v", 1))); + llvm::make_unique>("v", 1))); EXPECT_TRUE(notMatches( "class A { int c; int d; };", recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), @@ -4410,7 +4413,7 @@ TEST(HasAncestor, BindsRecursiveCombinations) { EXPECT_TRUE(matchAndVerifyResultTrue( "class C { class D { class E { class F { int y; }; }; }; };", fieldDecl(hasAncestor(recordDecl(hasAncestor(recordDecl().bind("r"))))), - new VerifyIdIsBoundTo("r", 1))); + llvm::make_unique>("r", 1))); } TEST(HasAncestor, BindsCombinationsWithHasDescendant) { @@ -4422,7 +4425,7 @@ TEST(HasAncestor, BindsCombinationsWithHasDescendant) { hasAncestor(recordDecl()))) ).bind("d") )), - new VerifyIdIsBoundTo("d", "E"))); + llvm::make_unique>("d", "E"))); } TEST(HasAncestor, MatchesClosestAncestor) { @@ -4436,7 +4439,7 @@ TEST(HasAncestor, MatchesClosestAncestor) { varDecl(hasName("x"), hasAncestor(functionDecl(hasParameter( 0, varDecl(hasType(asString("int"))))).bind("f"))).bind("v"), - new VerifyIdIsBoundTo("f", "g", 2))); + llvm::make_unique>("f", "g", 2))); } TEST(HasAncestor, MatchesInTemplateInstantiations) { @@ -4574,7 +4577,7 @@ TEST(HasParent, NoDuplicateParents) { EXPECT_FALSE(matchAndVerifyResultTrue( "template int Foo() { return 1 + 2; }\n" "int x = Foo() + Foo();", - stmt().bind("node"), new HasDuplicateParents())); + stmt().bind("node"), llvm::make_unique())); } TEST(TypeMatching, MatchesTypes) { @@ -4749,11 +4752,11 @@ TEST(TypeMatching, PointerTypes) { //EXPECT_TRUE(matchAndVerifyResultTrue( // "int* a;", // pointerTypeLoc(pointeeLoc(typeLoc().bind("loc"))), - // new VerifyIdIsBoundTo("loc", 1))); + // llvm::make_unique>("loc", 1))); //EXPECT_TRUE(matchAndVerifyResultTrue( // "int* a;", // pointerTypeLoc().bind("loc"), - // new VerifyIdIsBoundTo("loc", 1))); + // llvm::make_unique>("loc", 1))); EXPECT_TRUE(matches( "int** a;", loc(pointerType(pointee(qualType()))))); @@ -5011,14 +5014,15 @@ TEST(NNS, BindsNestedNameSpecifiers) { EXPECT_TRUE(matchAndVerifyResultTrue( "namespace ns { struct E { struct B {}; }; } ns::E::B b;", nestedNameSpecifier(specifiesType(asString("struct ns::E"))).bind("nns"), - new VerifyIdIsBoundTo("nns", "ns::struct E::"))); + llvm::make_unique>( + "nns", "ns::struct E::"))); } TEST(NNS, BindsNestedNameSpecifierLocs) { EXPECT_TRUE(matchAndVerifyResultTrue( "namespace ns { struct B {}; } ns::B b;", loc(nestedNameSpecifier()).bind("loc"), - new VerifyIdIsBoundTo("loc", 1))); + llvm::make_unique>("loc", 1))); } TEST(NNS, MatchesNestedNameSpecifierPrefixes) { @@ -5057,7 +5061,7 @@ TEST(NNS, DescendantsOfNestedNameSpecifiers) { Fragment, nestedNameSpecifier(specifiesType(asString("struct a::A::B")), forEach(nestedNameSpecifier().bind("x"))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); } TEST(NNS, NestedNameSpecifiersAsDescendants) { @@ -5073,7 +5077,7 @@ TEST(NNS, NestedNameSpecifiersAsDescendants) { functionDecl(hasName("f"), forEachDescendant(nestedNameSpecifier().bind("x"))), // Nested names: a, a::A and a::A::B. - new VerifyIdIsBoundTo("x", 3))); + llvm::make_unique>("x", 3))); } TEST(NNSLoc, DescendantsOfNestedNameSpecifierLocs) { @@ -5100,7 +5104,7 @@ TEST(NNSLoc, DescendantsOfNestedNameSpecifierLocs) { Fragment, nestedNameSpecifierLoc(loc(specifiesType(asString("struct a::A::B"))), forEach(nestedNameSpecifierLoc().bind("x"))), - new VerifyIdIsBoundTo("x", 1))); + llvm::make_unique>("x", 1))); } TEST(NNSLoc, NestedNameSpecifierLocsAsDescendants) { @@ -5116,7 +5120,7 @@ TEST(NNSLoc, NestedNameSpecifierLocsAsDescendants) { functionDecl(hasName("f"), forEachDescendant(nestedNameSpecifierLoc().bind("x"))), // Nested names: a, a::A and a::A::B. - new VerifyIdIsBoundTo("x", 3))); + llvm::make_unique>("x", 3))); } template class VerifyMatchOnNode : public BoundNodesCallback { @@ -5142,12 +5146,12 @@ private: TEST(MatchFinder, CanMatchDeclarationsRecursively) { EXPECT_TRUE(matchAndVerifyResultTrue( "class X { class Y {}; };", recordDecl(hasName("::X")).bind("X"), - new VerifyMatchOnNode( + llvm::make_unique>( "X", decl(hasDescendant(recordDecl(hasName("X::Y")).bind("Y"))), "Y"))); EXPECT_TRUE(matchAndVerifyResultFalse( "class X { class Y {}; };", recordDecl(hasName("::X")).bind("X"), - new VerifyMatchOnNode( + llvm::make_unique>( "X", decl(hasDescendant(recordDecl(hasName("X::Z")).bind("Z"))), "Z"))); } @@ -5155,22 +5159,22 @@ TEST(MatchFinder, CanMatchDeclarationsRecursively) { TEST(MatchFinder, CanMatchStatementsRecursively) { EXPECT_TRUE(matchAndVerifyResultTrue( "void f() { if (1) { for (;;) { } } }", ifStmt().bind("if"), - new VerifyMatchOnNode( + llvm::make_unique>( "if", stmt(hasDescendant(forStmt().bind("for"))), "for"))); EXPECT_TRUE(matchAndVerifyResultFalse( "void f() { if (1) { for (;;) { } } }", ifStmt().bind("if"), - new VerifyMatchOnNode( + llvm::make_unique>( "if", stmt(hasDescendant(declStmt().bind("decl"))), "decl"))); } TEST(MatchFinder, CanMatchSingleNodesRecursively) { EXPECT_TRUE(matchAndVerifyResultTrue( "class X { class Y {}; };", recordDecl(hasName("::X")).bind("X"), - new VerifyMatchOnNode( + llvm::make_unique>( "X", recordDecl(has(recordDecl(hasName("X::Y")).bind("Y"))), "Y"))); EXPECT_TRUE(matchAndVerifyResultFalse( "class X { class Y {}; };", recordDecl(hasName("::X")).bind("X"), - new VerifyMatchOnNode( + llvm::make_unique>( "X", recordDecl(has(recordDecl(hasName("X::Z")).bind("Z"))), "Z"))); } @@ -5217,14 +5221,14 @@ public: TEST(IsEqualTo, MatchesNodesByIdentity) { EXPECT_TRUE(matchAndVerifyResultTrue( "class X { class Y {}; };", recordDecl(hasName("::X::Y")).bind(""), - new VerifyAncestorHasChildIsEqual())); + llvm::make_unique>())); EXPECT_TRUE(matchAndVerifyResultTrue( "void f() { if (true) if(true) {} }", ifStmt().bind(""), - new VerifyAncestorHasChildIsEqual())); + llvm::make_unique>())); EXPECT_TRUE(matchAndVerifyResultTrue( "class X { class Y {} y; };", fieldDecl(hasName("y"), hasType(type().bind(""))).bind("decl"), - new VerifyAncestorHasChildIsEqual())); + llvm::make_unique>())); } TEST(MatchFinder, CheckProfiling) { @@ -5379,7 +5383,7 @@ TEST(EqualsBoundNodeMatcher, UsingForEachDescendant) { forEachDescendant(varDecl(hasType( qualType(equalsBoundNode("type")))).bind("decl"))), // Only i and j should match, not k. - new VerifyIdIsBoundTo("decl", 2))); + llvm::make_unique>("decl", 2))); } TEST(EqualsBoundNodeMatcher, FiltersMatchedCombinations) { @@ -5392,7 +5396,7 @@ TEST(EqualsBoundNodeMatcher, FiltersMatchedCombinations) { functionDecl( hasName("f"), forEachDescendant(varDecl().bind("d")), forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))), - new VerifyIdIsBoundTo("d", 5))); + llvm::make_unique>("d", 5))); } TEST(EqualsBoundNodeMatcher, UnlessDescendantsOfAncestorsMatch) { @@ -5409,7 +5413,7 @@ TEST(EqualsBoundNodeMatcher, UnlessDescendantsOfAncestorsMatch) { callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))), on(declRefExpr(to(varDecl(equalsBoundNode("var"))))))))))) .bind("data"), - new VerifyIdIsBoundTo("data", 1))); + llvm::make_unique>("data", 1))); EXPECT_FALSE(matches( "struct StringRef { int size() const; const char* data() const; };" diff --git a/unittests/ASTMatchers/ASTMatchersTest.h b/unittests/ASTMatchers/ASTMatchersTest.h index fe8fcfd589..7c18aee778 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.h +++ b/unittests/ASTMatchers/ASTMatchersTest.h @@ -37,8 +37,8 @@ public: // If 'FindResultVerifier' is NULL, sets *Verified to true when Run is called. class VerifyMatch : public MatchFinder::MatchCallback { public: - VerifyMatch(BoundNodesCallback *FindResultVerifier, bool *Verified) - : Verified(Verified), FindResultReviewer(FindResultVerifier) {} + VerifyMatch(std::unique_ptr FindResultVerifier, bool *Verified) + : Verified(Verified), FindResultReviewer(std::move(FindResultVerifier)) {} void run(const MatchFinder::MatchResult &Result) override { if (FindResultReviewer != nullptr) { @@ -55,7 +55,7 @@ public: private: bool *const Verified; - BoundNodesCallback *const FindResultReviewer; + const std::unique_ptr FindResultReviewer; }; template @@ -222,12 +222,11 @@ testing::AssertionResult notMatchesWithCuda(const std::string &Code, template testing::AssertionResult matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher, - BoundNodesCallback *FindResultVerifier, + std::unique_ptr FindResultVerifier, bool ExpectResult) { - std::unique_ptr ScopedVerifier(FindResultVerifier); bool VerifiedResult = false; MatchFinder Finder; - VerifyMatch VerifyVerifiedResult(FindResultVerifier, &VerifiedResult); + VerifyMatch VerifyVerifiedResult(std::move(FindResultVerifier), &VerifiedResult); Finder.addMatcher(AMatcher, &VerifyVerifiedResult); std::unique_ptr Factory( newFrontendActionFactory(&Finder)); @@ -266,17 +265,17 @@ matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher, template testing::AssertionResult matchAndVerifyResultTrue(const std::string &Code, const T &AMatcher, - BoundNodesCallback *FindResultVerifier) { + std::unique_ptr FindResultVerifier) { return matchAndVerifyResultConditionally( - Code, AMatcher, FindResultVerifier, true); + Code, AMatcher, std::move(FindResultVerifier), true); } template testing::AssertionResult matchAndVerifyResultFalse(const std::string &Code, const T &AMatcher, - BoundNodesCallback *FindResultVerifier) { + std::unique_ptr FindResultVerifier) { return matchAndVerifyResultConditionally( - Code, AMatcher, FindResultVerifier, false); + Code, AMatcher, std::move(FindResultVerifier), false); } } // end namespace ast_matchers -- 2.40.0