r266986 - Clarify memory ownership semantics; NFC.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 21 06:51:08 PDT 2016
Author: aaronballman
Date: Thu Apr 21 08:51:07 2016
New Revision: 266986
URL: http://llvm.org/viewvc/llvm-project?rev=266986&view=rev
Log:
Clarify memory ownership semantics; NFC.
Patch by Clement Courbet
Modified:
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=266986&r1=266985&r2=266986&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Thu Apr 21 08:51:07 2016
@@ -830,7 +830,7 @@ TEST(HasDescendant, MatchesDescendantTyp
"void f() { int a; float c; int d; int e; }",
functionDecl(forEachDescendant(
varDecl(hasDescendant(isInteger())).bind("x"))),
- new VerifyIdIsBoundTo<Decl>("x", 3)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 3)));
}
TEST(HasDescendant, MatchesDescendantsOfTypes) {
@@ -845,7 +845,7 @@ TEST(HasDescendant, MatchesDescendantsOf
EXPECT_TRUE(matchAndVerifyResultTrue(
"void f() { int*** i; }",
qualType(asString("int ***"), forEachDescendant(pointerType().bind("x"))),
- new VerifyIdIsBoundTo<Type>("x", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<Type>>("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<QualType>("x", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<QualType>>("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<CXXRecordDecl>("x")));
+ ClassX, llvm::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("x")));
EXPECT_TRUE(matchAndVerifyResultFalse("class X {};",
- ClassX, new VerifyIdIsBoundTo<CXXRecordDecl>("other-id")));
+ ClassX, llvm::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("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<Decl>("b")));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("b")));
StatementMatcher MethodX =
callExpr(callee(cxxMethodDecl(hasName("x")))).bind("x");
EXPECT_TRUE(matchAndVerifyResultTrue("class A { void x() { x(); } };",
MethodX,
- new VerifyIdIsBoundTo<CXXMemberCallExpr>("x")));
+ llvm::make_unique<VerifyIdIsBoundTo<CXXMemberCallExpr>>("x")));
}
TEST(Matcher, BindTheSameNameInAlternatives) {
@@ -1023,7 +1023,7 @@ TEST(Matcher, BindTheSameNameInAlternati
// The second branch binds x to f() and succeeds.
"int f() { return 0 + f(); }",
matcher,
- new VerifyIdIsBoundTo<CallExpr>("x")));
+ llvm::make_unique<VerifyIdIsBoundTo<CallExpr>>("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<Decl>("x", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 2)));
}
TEST(HasDeclaration, HasDeclarationOfEnumType) {
@@ -1313,7 +1313,7 @@ TEST(Matcher, NestedOverloadedOperatorCa
"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<CXXOperatorCallExpr>("x", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<CXXOperatorCallExpr>>("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, MatchesCX
" int y = 1;"
" S1[y];"
"}",
- CallExpr, new VerifyIdIsBoundTo<ParmVarDecl>("param", 1)));
+ CallExpr, llvm::make_unique<VerifyIdIsBoundTo<ParmVarDecl>>("param", 1)));
StatementMatcher CallExpr2 =
callExpr(forEachArgumentWithParam(ArgumentY, IntParam));
@@ -1706,7 +1706,7 @@ TEST(ForEachArgumentWithParam, MatchesCX
" int y = 1;"
" S::g(y);"
"}",
- CallExpr2, new VerifyIdIsBoundTo<ParmVarDecl>("param", 1)));
+ CallExpr2, llvm::make_unique<VerifyIdIsBoundTo<ParmVarDecl>>("param", 1)));
}
TEST(ForEachArgumentWithParam, MatchesCallExpr) {
@@ -1718,17 +1718,19 @@ TEST(ForEachArgumentWithParam, MatchesCa
EXPECT_TRUE(
matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr,
- new VerifyIdIsBoundTo<ParmVarDecl>("param")));
+ llvm::make_unique<VerifyIdIsBoundTo<ParmVarDecl>>(
+ "param")));
EXPECT_TRUE(
matchAndVerifyResultTrue("void f(int i) { int y; f(y); }", CallExpr,
- new VerifyIdIsBoundTo<DeclRefExpr>("arg")));
+ llvm::make_unique<VerifyIdIsBoundTo<DeclRefExpr>>(
+ "arg")));
EXPECT_TRUE(matchAndVerifyResultTrue(
"void f(int i, int j) { int y; f(y, y); }", CallExpr,
- new VerifyIdIsBoundTo<ParmVarDecl>("param", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<ParmVarDecl>>("param", 2)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"void f(int i, int j) { int y; f(y, y); }", CallExpr,
- new VerifyIdIsBoundTo<DeclRefExpr>("arg", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<DeclRefExpr>>("arg", 2)));
}
TEST(ForEachArgumentWithParam, MatchesConstructExpr) {
@@ -1744,7 +1746,8 @@ TEST(ForEachArgumentWithParam, MatchesCo
"};"
"int y = 0;"
"C Obj(y);",
- ConstructExpr, new VerifyIdIsBoundTo<ParmVarDecl>("param")));
+ ConstructExpr,
+ llvm::make_unique<VerifyIdIsBoundTo<ParmVarDecl>>("param")));
}
TEST(ForEachArgumentWithParam, HandlesBoundNodesForNonMatches) {
@@ -1761,7 +1764,7 @@ TEST(ForEachArgumentWithParam, HandlesBo
forEachDescendant(varDecl().bind("v")),
forEachDescendant(callExpr(forEachArgumentWithParam(
declRefExpr(to(decl(equalsBoundNode("v")))), parmVarDecl())))),
- new VerifyIdIsBoundTo<VarDecl>("v", 4)));
+ llvm::make_unique<VerifyIdIsBoundTo<VarDecl>>("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<Decl>("b")));
+ HasClassB, llvm::make_unique<VerifyIdIsBoundTo<Decl>>("b")));
EXPECT_TRUE(matchAndVerifyResultFalse("class A { class B {}; };",
- HasClassB, new VerifyIdIsBoundTo<Decl>("a")));
+ HasClassB, llvm::make_unique<VerifyIdIsBoundTo<Decl>>("a")));
EXPECT_TRUE(matchAndVerifyResultFalse("class A { class C {}; };",
- HasClassB, new VerifyIdIsBoundTo<Decl>("b")));
+ HasClassB, llvm::make_unique<VerifyIdIsBoundTo<Decl>>("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<Decl>("b")));
+ HasClassB, llvm::make_unique<VerifyIdIsBoundTo<Decl>>("b")));
EXPECT_TRUE(matchAndVerifyResultFalse("class A { class B {}; };",
- HasClassB, new VerifyIdIsBoundTo<Decl>("a")));
+ HasClassB, llvm::make_unique<VerifyIdIsBoundTo<Decl>>("a")));
EXPECT_TRUE(matchAndVerifyResultFalse("class A { class C {}; };",
- HasClassB, new VerifyIdIsBoundTo<Decl>("b")));
+ HasClassB, llvm::make_unique<VerifyIdIsBoundTo<Decl>>("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<CaseStmt>("x", 3)));
+ llvm::make_unique<VerifyIdIsBoundTo<CaseStmt>>("x", 3)));
}
TEST(ForEachConstructorInitializer, MatchesInitializers) {
@@ -3968,13 +3971,13 @@ TEST(HasConditionVariableStatement, Matc
TEST(ForEach, BindsOneNode) {
EXPECT_TRUE(matchAndVerifyResultTrue("class C { int x; };",
recordDecl(hasName("C"), forEach(fieldDecl(hasName("x")).bind("x"))),
- new VerifyIdIsBoundTo<FieldDecl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("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<FieldDecl>("f", 3)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("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<FieldDecl>("f", 4)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("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<FieldDecl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("x", 1)));
}
TEST(ForEachDescendant, NestedForEachDescendant) {
@@ -3998,7 +4001,7 @@ TEST(ForEachDescendant, NestedForEachDes
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A { class B { class C {}; }; };",
recordDecl(hasName("A"), anyOf(m, forEachDescendant(m))),
- new VerifyIdIsBoundTo<Decl>("x", "C")));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("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, NestedForEachDes
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A { class B { class C {}; }; };",
recordDecl(hasName("A"), allOf(hasDescendant(m), anyOf(m, anything()))),
- new VerifyIdIsBoundTo<Decl>("x", "C")));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", "C")));
}
TEST(ForEachDescendant, BindsMultipleNodes) {
@@ -4014,7 +4017,7 @@ TEST(ForEachDescendant, BindsMultipleNod
"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<FieldDecl>("f", 4)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("f", 4)));
}
TEST(ForEachDescendant, BindsRecursiveCombinations) {
@@ -4023,7 +4026,7 @@ TEST(ForEachDescendant, BindsRecursiveCo
" class E { class F { class G { int y; int z; }; }; }; }; };",
recordDecl(hasName("C"), forEachDescendant(recordDecl(
forEachDescendant(fieldDecl().bind("f"))))),
- new VerifyIdIsBoundTo<FieldDecl>("f", 8)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("f", 8)));
}
TEST(ForEachDescendant, BindsCombinations) {
@@ -4032,13 +4035,13 @@ TEST(ForEachDescendant, BindsCombination
"(true) {} }",
compoundStmt(forEachDescendant(ifStmt().bind("if")),
forEachDescendant(whileStmt().bind("while"))),
- new VerifyIdIsBoundTo<IfStmt>("if", 6)));
+ llvm::make_unique<VerifyIdIsBoundTo<IfStmt>>("if", 6)));
}
TEST(Has, DoesNotDeleteBindings) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"class X { int a; };", recordDecl(decl().bind("x"), has(fieldDecl())),
- new VerifyIdIsBoundTo<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 1)));
}
TEST(LoopingMatchers, DoNotOverwritePreviousMatchResultOnFailure) {
@@ -4066,100 +4069,100 @@ TEST(LoopingMatchers, DoNotOverwritePrev
recordDecl(
recordDecl().bind("x"), hasName("::X"),
anyOf(forEachDescendant(recordDecl(hasName("Y"))), anything())),
- new VerifyIdIsBoundTo<CXXRecordDecl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"class X {};", recordDecl(recordDecl().bind("x"), hasName("::X"),
anyOf(unless(anything()), anything())),
- new VerifyIdIsBoundTo<CXXRecordDecl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"template<typename T1, typename T2> class X {}; X<float, int> x;",
classTemplateSpecializationDecl(
decl().bind("x"),
hasAnyTemplateArgument(refersToType(asString("int")))),
- new VerifyIdIsBoundTo<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"class X { void f(); void g(); };",
cxxRecordDecl(decl().bind("x"), hasMethod(hasName("g"))),
- new VerifyIdIsBoundTo<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("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<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"void x(int, int) { x(0, 42); }",
callExpr(expr().bind("x"), hasAnyArgument(integerLiteral(equals(42)))),
- new VerifyIdIsBoundTo<Expr>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Expr>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"void x(int, int y) {}",
functionDecl(decl().bind("x"), hasAnyParameter(hasName("y"))),
- new VerifyIdIsBoundTo<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"void x() { return; if (true) {} }",
functionDecl(decl().bind("x"),
has(compoundStmt(hasAnySubstatement(ifStmt())))),
- new VerifyIdIsBoundTo<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("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<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A{}; class B{}; class C : B, A {};",
cxxRecordDecl(decl().bind("x"), isDerivedFrom("::A")),
- new VerifyIdIsBoundTo<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("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<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A { class B { void f() {} }; };",
functionDecl(decl().bind("x"), hasAncestor(recordDecl(hasName("::A")))),
- new VerifyIdIsBoundTo<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"template <typename T> struct A { struct B {"
" void f() { if(true) {} }"
"}; };"
"void t() { A<int>::B b; b.f(); }",
ifStmt(stmt().bind("x"), hasAncestor(recordDecl(hasName("::A")))),
- new VerifyIdIsBoundTo<Stmt>("x", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<Stmt>>("x", 2)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A {};",
recordDecl(hasName("::A"), decl().bind("x"), unless(hasName("fooble"))),
- new VerifyIdIsBoundTo<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("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<Decl>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("x", 1)));
}
TEST(ForEachDescendant, BindsCorrectNodes) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"class C { void f(); int i; };",
recordDecl(hasName("C"), forEachDescendant(decl().bind("decl"))),
- new VerifyIdIsBoundTo<FieldDecl>("decl", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("decl", 1)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"class C { void f() {} int i; };",
recordDecl(hasName("C"), forEachDescendant(decl().bind("decl"))),
- new VerifyIdIsBoundTo<FunctionDecl>("decl", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<FunctionDecl>>("decl", 1)));
}
TEST(FindAll, BindsNodeOnMatch) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A {};",
recordDecl(hasName("::A"), findAll(recordDecl(hasName("::A")).bind("v"))),
- new VerifyIdIsBoundTo<CXXRecordDecl>("v", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("v", 1)));
}
TEST(FindAll, BindsDescendantNodeOnMatch) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A { int a; int b; };",
recordDecl(hasName("::A"), findAll(fieldDecl().bind("v"))),
- new VerifyIdIsBoundTo<FieldDecl>("v", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("v", 2)));
}
TEST(FindAll, BindsNodeAndDescendantNodesOnOneMatch) {
@@ -4168,12 +4171,12 @@ TEST(FindAll, BindsNodeAndDescendantNode
recordDecl(hasName("::A"),
findAll(decl(anyOf(recordDecl(hasName("::A")).bind("v"),
fieldDecl().bind("v"))))),
- new VerifyIdIsBoundTo<Decl>("v", 3)));
+ llvm::make_unique<VerifyIdIsBoundTo<Decl>>("v", 3)));
EXPECT_TRUE(matchAndVerifyResultTrue(
"class A { class B {}; class C {}; };",
recordDecl(hasName("::A"), findAll(recordDecl(isDefinition()).bind("v"))),
- new VerifyIdIsBoundTo<CXXRecordDecl>("v", 3)));
+ llvm::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("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<FieldDecl>("v", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("v", 2)));
}
TEST(EachOf, BehavesLikeAnyOfUnlessBothMatch) {
@@ -4189,12 +4192,12 @@ TEST(EachOf, BehavesLikeAnyOfUnlessBothM
"class A { int a; int c; };",
recordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")),
has(fieldDecl(hasName("b")).bind("v")))),
- new VerifyIdIsBoundTo<FieldDecl>("v", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("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<FieldDecl>("v", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<FieldDecl>>("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, BindsRecursiveCombinat
EXPECT_TRUE(matchAndVerifyResultTrue(
"class C { class D { class E { class F { int y; }; }; }; };",
fieldDecl(hasAncestor(recordDecl(hasAncestor(recordDecl().bind("r"))))),
- new VerifyIdIsBoundTo<CXXRecordDecl>("r", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("r", 1)));
}
TEST(HasAncestor, BindsCombinationsWithHasDescendant) {
@@ -4422,7 +4425,7 @@ TEST(HasAncestor, BindsCombinationsWithH
hasAncestor(recordDecl())))
).bind("d")
)),
- new VerifyIdIsBoundTo<CXXRecordDecl>("d", "E")));
+ llvm::make_unique<VerifyIdIsBoundTo<CXXRecordDecl>>("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<FunctionDecl>("f", "g", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<FunctionDecl>>("f", "g", 2)));
}
TEST(HasAncestor, MatchesInTemplateInstantiations) {
@@ -4574,7 +4577,7 @@ TEST(HasParent, NoDuplicateParents) {
EXPECT_FALSE(matchAndVerifyResultTrue(
"template <typename T> int Foo() { return 1 + 2; }\n"
"int x = Foo<int>() + Foo<unsigned>();",
- stmt().bind("node"), new HasDuplicateParents()));
+ stmt().bind("node"), llvm::make_unique<HasDuplicateParents>()));
}
TEST(TypeMatching, MatchesTypes) {
@@ -4749,11 +4752,11 @@ TEST(TypeMatching, PointerTypes) {
//EXPECT_TRUE(matchAndVerifyResultTrue(
// "int* a;",
// pointerTypeLoc(pointeeLoc(typeLoc().bind("loc"))),
- // new VerifyIdIsBoundTo<TypeLoc>("loc", 1)));
+ // llvm::make_unique<VerifyIdIsBoundTo<TypeLoc>>("loc", 1)));
//EXPECT_TRUE(matchAndVerifyResultTrue(
// "int* a;",
// pointerTypeLoc().bind("loc"),
- // new VerifyIdIsBoundTo<TypeLoc>("loc", 1)));
+ // llvm::make_unique<VerifyIdIsBoundTo<TypeLoc>>("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<NestedNameSpecifier>("nns", "ns::struct E::")));
+ llvm::make_unique<VerifyIdIsBoundTo<NestedNameSpecifier>>(
+ "nns", "ns::struct E::")));
}
TEST(NNS, BindsNestedNameSpecifierLocs) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"namespace ns { struct B {}; } ns::B b;",
loc(nestedNameSpecifier()).bind("loc"),
- new VerifyIdIsBoundTo<NestedNameSpecifierLoc>("loc", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<NestedNameSpecifierLoc>>("loc", 1)));
}
TEST(NNS, MatchesNestedNameSpecifierPrefixes) {
@@ -5057,7 +5061,7 @@ TEST(NNS, DescendantsOfNestedNameSpecifi
Fragment,
nestedNameSpecifier(specifiesType(asString("struct a::A::B")),
forEach(nestedNameSpecifier().bind("x"))),
- new VerifyIdIsBoundTo<NestedNameSpecifier>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<NestedNameSpecifier>>("x", 1)));
}
TEST(NNS, NestedNameSpecifiersAsDescendants) {
@@ -5073,7 +5077,7 @@ TEST(NNS, NestedNameSpecifiersAsDescenda
functionDecl(hasName("f"),
forEachDescendant(nestedNameSpecifier().bind("x"))),
// Nested names: a, a::A and a::A::B.
- new VerifyIdIsBoundTo<NestedNameSpecifier>("x", 3)));
+ llvm::make_unique<VerifyIdIsBoundTo<NestedNameSpecifier>>("x", 3)));
}
TEST(NNSLoc, DescendantsOfNestedNameSpecifierLocs) {
@@ -5100,7 +5104,7 @@ TEST(NNSLoc, DescendantsOfNestedNameSpec
Fragment,
nestedNameSpecifierLoc(loc(specifiesType(asString("struct a::A::B"))),
forEach(nestedNameSpecifierLoc().bind("x"))),
- new VerifyIdIsBoundTo<NestedNameSpecifierLoc>("x", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<NestedNameSpecifierLoc>>("x", 1)));
}
TEST(NNSLoc, NestedNameSpecifierLocsAsDescendants) {
@@ -5116,7 +5120,7 @@ TEST(NNSLoc, NestedNameSpecifierLocsAsDe
functionDecl(hasName("f"),
forEachDescendant(nestedNameSpecifierLoc().bind("x"))),
// Nested names: a, a::A and a::A::B.
- new VerifyIdIsBoundTo<NestedNameSpecifierLoc>("x", 3)));
+ llvm::make_unique<VerifyIdIsBoundTo<NestedNameSpecifierLoc>>("x", 3)));
}
template <typename T> 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<clang::Decl>(
+ llvm::make_unique<VerifyMatchOnNode<Decl>>(
"X", decl(hasDescendant(recordDecl(hasName("X::Y")).bind("Y"))),
"Y")));
EXPECT_TRUE(matchAndVerifyResultFalse(
"class X { class Y {}; };", recordDecl(hasName("::X")).bind("X"),
- new VerifyMatchOnNode<clang::Decl>(
+ llvm::make_unique<VerifyMatchOnNode<Decl>>(
"X", decl(hasDescendant(recordDecl(hasName("X::Z")).bind("Z"))),
"Z")));
}
@@ -5155,22 +5159,22 @@ TEST(MatchFinder, CanMatchDeclarationsRe
TEST(MatchFinder, CanMatchStatementsRecursively) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"void f() { if (1) { for (;;) { } } }", ifStmt().bind("if"),
- new VerifyMatchOnNode<clang::Stmt>(
+ llvm::make_unique<VerifyMatchOnNode<Stmt>>(
"if", stmt(hasDescendant(forStmt().bind("for"))), "for")));
EXPECT_TRUE(matchAndVerifyResultFalse(
"void f() { if (1) { for (;;) { } } }", ifStmt().bind("if"),
- new VerifyMatchOnNode<clang::Stmt>(
+ llvm::make_unique<VerifyMatchOnNode<Stmt>>(
"if", stmt(hasDescendant(declStmt().bind("decl"))), "decl")));
}
TEST(MatchFinder, CanMatchSingleNodesRecursively) {
EXPECT_TRUE(matchAndVerifyResultTrue(
"class X { class Y {}; };", recordDecl(hasName("::X")).bind("X"),
- new VerifyMatchOnNode<clang::Decl>(
+ llvm::make_unique<VerifyMatchOnNode<Decl>>(
"X", recordDecl(has(recordDecl(hasName("X::Y")).bind("Y"))), "Y")));
EXPECT_TRUE(matchAndVerifyResultFalse(
"class X { class Y {}; };", recordDecl(hasName("::X")).bind("X"),
- new VerifyMatchOnNode<clang::Decl>(
+ llvm::make_unique<VerifyMatchOnNode<Decl>>(
"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<CXXRecordDecl>()));
+ llvm::make_unique<VerifyAncestorHasChildIsEqual<CXXRecordDecl>>()));
EXPECT_TRUE(matchAndVerifyResultTrue(
"void f() { if (true) if(true) {} }", ifStmt().bind(""),
- new VerifyAncestorHasChildIsEqual<IfStmt>()));
+ llvm::make_unique<VerifyAncestorHasChildIsEqual<IfStmt>>()));
EXPECT_TRUE(matchAndVerifyResultTrue(
"class X { class Y {} y; };",
fieldDecl(hasName("y"), hasType(type().bind(""))).bind("decl"),
- new VerifyAncestorHasChildIsEqual<Type>()));
+ llvm::make_unique<VerifyAncestorHasChildIsEqual<Type>>()));
}
TEST(MatchFinder, CheckProfiling) {
@@ -5379,7 +5383,7 @@ TEST(EqualsBoundNodeMatcher, UsingForEac
forEachDescendant(varDecl(hasType(
qualType(equalsBoundNode("type")))).bind("decl"))),
// Only i and j should match, not k.
- new VerifyIdIsBoundTo<VarDecl>("decl", 2)));
+ llvm::make_unique<VerifyIdIsBoundTo<VarDecl>>("decl", 2)));
}
TEST(EqualsBoundNodeMatcher, FiltersMatchedCombinations) {
@@ -5392,7 +5396,7 @@ TEST(EqualsBoundNodeMatcher, FiltersMatc
functionDecl(
hasName("f"), forEachDescendant(varDecl().bind("d")),
forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))),
- new VerifyIdIsBoundTo<VarDecl>("d", 5)));
+ llvm::make_unique<VerifyIdIsBoundTo<VarDecl>>("d", 5)));
}
TEST(EqualsBoundNodeMatcher, UnlessDescendantsOfAncestorsMatch) {
@@ -5409,7 +5413,7 @@ TEST(EqualsBoundNodeMatcher, UnlessDesce
callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))),
on(declRefExpr(to(varDecl(equalsBoundNode("var")))))))))))
.bind("data"),
- new VerifyIdIsBoundTo<Expr>("data", 1)));
+ llvm::make_unique<VerifyIdIsBoundTo<Expr>>("data", 1)));
EXPECT_FALSE(matches(
"struct StringRef { int size() const; const char* data() const; };"
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h?rev=266986&r1=266985&r2=266986&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h Thu Apr 21 08:51:07 2016
@@ -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<BoundNodesCallback> 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<BoundNodesCallback> FindResultReviewer;
};
template <typename T>
@@ -222,12 +222,11 @@ testing::AssertionResult notMatchesWithC
template <typename T>
testing::AssertionResult
matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher,
- BoundNodesCallback *FindResultVerifier,
+ std::unique_ptr<BoundNodesCallback> FindResultVerifier,
bool ExpectResult) {
- std::unique_ptr<BoundNodesCallback> ScopedVerifier(FindResultVerifier);
bool VerifiedResult = false;
MatchFinder Finder;
- VerifyMatch VerifyVerifiedResult(FindResultVerifier, &VerifiedResult);
+ VerifyMatch VerifyVerifiedResult(std::move(FindResultVerifier), &VerifiedResult);
Finder.addMatcher(AMatcher, &VerifyVerifiedResult);
std::unique_ptr<FrontendActionFactory> Factory(
newFrontendActionFactory(&Finder));
@@ -266,17 +265,17 @@ matchAndVerifyResultConditionally(const
template <typename T>
testing::AssertionResult
matchAndVerifyResultTrue(const std::string &Code, const T &AMatcher,
- BoundNodesCallback *FindResultVerifier) {
+ std::unique_ptr<BoundNodesCallback> FindResultVerifier) {
return matchAndVerifyResultConditionally(
- Code, AMatcher, FindResultVerifier, true);
+ Code, AMatcher, std::move(FindResultVerifier), true);
}
template <typename T>
testing::AssertionResult
matchAndVerifyResultFalse(const std::string &Code, const T &AMatcher,
- BoundNodesCallback *FindResultVerifier) {
+ std::unique_ptr<BoundNodesCallback> FindResultVerifier) {
return matchAndVerifyResultConditionally(
- Code, AMatcher, FindResultVerifier, false);
+ Code, AMatcher, std::move(FindResultVerifier), false);
}
} // end namespace ast_matchers
More information about the cfe-commits
mailing list