Index: unittests/Analysis/ExprMutationAnalyzerTest.cpp =================================================================== --- unittests/Analysis/ExprMutationAnalyzerTest.cpp +++ unittests/Analysis/ExprMutationAnalyzerTest.cpp @@ -29,6 +29,18 @@ using ExprMatcher = internal::Matcher; using StmtMatcher = internal::Matcher; +std::unique_ptr +buildASTFromCodeWithArgs(const Twine &Code, + const std::vector &Args) { + auto AST = tooling::buildASTFromCodeWithArgs(Code, Args); + EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred()); + return AST; +} + +std::unique_ptr buildASTFromCode(const Twine &Code) { + return buildASTFromCodeWithArgs(Code, {}); +} + ExprMatcher declRefTo(StringRef Name) { return declRefExpr(to(namedDecl(hasName(Name)))); } @@ -83,12 +95,12 @@ "template T&& " "forward(typename remove_reference::type& t) noexcept { return t; }" "template T&& " - "forward(typename remove_reference::type&&) noexcept { return t; } }"; + "forward(typename remove_reference::type&& t) noexcept { return t; } }"; } // namespace TEST(ExprMutationAnalyzerTest, Trivial) { - const auto AST = tooling::buildASTFromCode("void f() { int x; x; }"); + const auto AST = buildASTFromCode("void f() { int x; x; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); @@ -98,8 +110,7 @@ TEST_P(AssignmentTest, AssignmentModifies) { const std::string ModExpr = "x " + GetParam() + " 10"; - const auto AST = - tooling::buildASTFromCode("void f() { int x; " + ModExpr + "; }"); + const auto AST = buildASTFromCode("void f() { int x; " + ModExpr + "; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre(ModExpr)); @@ -113,8 +124,7 @@ TEST_P(IncDecTest, IncDecModifies) { const std::string ModExpr = GetParam(); - const auto AST = - tooling::buildASTFromCode("void f() { int x; " + ModExpr + "; }"); + const auto AST = buildASTFromCode("void f() { int x; " + ModExpr + "; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre(ModExpr)); @@ -124,7 +134,7 @@ Values("++x", "--x", "x++", "x--"), ); TEST(ExprMutationAnalyzerTest, NonConstMemberFunc) { - const auto AST = tooling::buildASTFromCode( + const auto AST = buildASTFromCode( "void f() { struct Foo { void mf(); }; Foo x; x.mf(); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -132,7 +142,7 @@ } TEST(ExprMutationAnalyzerTest, AssumedNonConstMemberFunc) { - auto AST = tooling::buildASTFromCodeWithArgs( + auto AST = buildASTFromCodeWithArgs( "struct X { template void mf(); };" "template void f() { X x; x.mf(); }", {"-fno-delayed-template-parsing"}); @@ -140,13 +150,12 @@ match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()")); - AST = tooling::buildASTFromCodeWithArgs( - "template void f() { T x; x.mf(); }", - {"-fno-delayed-template-parsing"}); + AST = buildASTFromCodeWithArgs("template void f() { T x; x.mf(); }", + {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.mf()")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "template struct X;" "template void f() { X x; x.mf(); }", {"-fno-delayed-template-parsing"}); @@ -155,7 +164,7 @@ } TEST(ExprMutationAnalyzerTest, ConstMemberFunc) { - const auto AST = tooling::buildASTFromCode( + const auto AST = buildASTFromCode( "void f() { struct Foo { void mf() const; }; Foo x; x.mf(); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -163,7 +172,7 @@ } TEST(ExprMutationAnalyzerTest, NonConstOperator) { - const auto AST = tooling::buildASTFromCode( + const auto AST = buildASTFromCode( "void f() { struct Foo { Foo& operator=(int); }; Foo x; x = 10; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -171,7 +180,7 @@ } TEST(ExprMutationAnalyzerTest, ConstOperator) { - const auto AST = tooling::buildASTFromCode( + const auto AST = buildASTFromCode( "void f() { struct Foo { int operator()() const; }; Foo x; x(); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -179,280 +188,254 @@ } TEST(ExprMutationAnalyzerTest, ByValueArgument) { - auto AST = - tooling::buildASTFromCode("void g(int); void f() { int x; g(x); }"); + auto AST = buildASTFromCode("void g(int); void f() { int x; g(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("void g(int*); void f() { int* x; g(x); }"); + AST = buildASTFromCode("void g(int*); void f() { int* x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("typedef int* IntPtr;" - "void g(IntPtr); void f() { int* x; g(x); }"); + AST = buildASTFromCode("typedef int* IntPtr;" + "void g(IntPtr); void f() { int* x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { struct A {}; A operator+(A, int); A x; x + 1; }"); + AST = buildASTFromCode( + "struct A {}; A operator+(A, int) {} void f() { A x; x + 1; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { struct A { A(int); }; int x; A y(x); }"); + AST = buildASTFromCode("void f() { struct A { A(int); }; int x; A y(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { struct A { A(); A(A); }; A x; A y(x); }"); + AST = buildASTFromCode("struct A { A(); A& operator=(A); };" + "void f() { A x, y; y = x; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, ByConstValueArgument) { - auto AST = - tooling::buildASTFromCode("void g(const int); void f() { int x; g(x); }"); + auto AST = buildASTFromCode("void g(const int); void f() { int x; g(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void g(int* const); void f() { int* x; g(x); }"); + AST = buildASTFromCode("void g(int* const); void f() { int* x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = - tooling::buildASTFromCode("typedef int* const CIntPtr;" - "void g(CIntPtr); void f() { int* x; g(x); }"); + AST = buildASTFromCode("typedef int* const CIntPtr;" + "void g(CIntPtr); void f() { int* x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { struct A {}; A operator+(const A, int); A x; x + 1; }"); + AST = buildASTFromCode( + "struct A {}; A operator+(const A, int) {} void f() { A x; x + 1; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "void f() { struct A { A(const int); }; int x; A y(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - - AST = tooling::buildASTFromCode( - "void f() { struct A { A(); A(const A); }; A x; A y(x); }"); - Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); - EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, ByNonConstRefArgument) { - auto AST = - tooling::buildASTFromCode("void g(int&); void f() { int x; g(x); }"); + auto AST = buildASTFromCode("void g(int&); void f() { int x; g(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = tooling::buildASTFromCode("typedef int& IntRef;" - "void g(IntRef); void f() { int x; g(x); }"); + AST = buildASTFromCode("typedef int& IntRef;" + "void g(IntRef); void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = - tooling::buildASTFromCode("template using TRef = T&;" - "void g(TRef); void f() { int x; g(x); }"); + AST = buildASTFromCode("template using TRef = T&;" + "void g(TRef); void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "template struct identity { using type = T; };" "template void g(typename identity::type);" "void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = - tooling::buildASTFromCode("typedef int* IntPtr;" - "void g(IntPtr&); void f() { int* x; g(x); }"); + AST = buildASTFromCode("typedef int* IntPtr;" + "void g(IntPtr&); void f() { int* x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = tooling::buildASTFromCode( - "typedef int* IntPtr; typedef IntPtr& IntPtrRef;" - "void g(IntPtrRef); void f() { int* x; g(x); }"); + AST = buildASTFromCode("typedef int* IntPtr; typedef IntPtr& IntPtrRef;" + "void g(IntPtrRef); void f() { int* x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = tooling::buildASTFromCode( - "void f() { struct A {}; A operator+(A&, int); A x; x + 1; }"); + AST = buildASTFromCode( + "struct A {}; A operator+(A&, int) {} void f() { A x; x + 1; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x + 1")); - AST = tooling::buildASTFromCode( - "void f() { struct A { A(int&); }; int x; A y(x); }"); + AST = buildASTFromCode("void f() { struct A { A(int&); }; int x; A y(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x")); - AST = tooling::buildASTFromCode( - "void f() { struct A { A(); A(A&); }; A x; A y(x); }"); + AST = buildASTFromCode("void f() { struct A { A(); A(A&); }; A x; A y(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x")); } TEST(ExprMutationAnalyzerTest, ByConstRefArgument) { - auto AST = tooling::buildASTFromCode( - "void g(const int&); void f() { int x; g(x); }"); + auto AST = buildASTFromCode("void g(const int&); void f() { int x; g(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("typedef const int& CIntRef;" - "void g(CIntRef); void f() { int x; g(x); }"); + AST = buildASTFromCode("typedef const int& CIntRef;" + "void g(CIntRef); void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "template using CTRef = const T&;" - "void g(CTRef); void f() { int x; g(x); }"); + AST = buildASTFromCode("template using CTRef = const T&;" + "void g(CTRef); void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "template struct identity { using type = T; };" - "template " - "void g(typename identity::type);" - "void f() { int x; g(x); }"); + AST = + buildASTFromCode("template struct identity { using type = T; };" + "template " + "void g(typename identity::type);" + "void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { struct A {}; A operator+(const A&, int); A x; x + 1; }"); + AST = buildASTFromCode( + "struct A {}; A operator+(const A&, int) {} void f() { A x; x + 1; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "void f() { struct A { A(const int&); }; int x; A y(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "void f() { struct A { A(); A(const A&); }; A x; A y(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, ByNonConstRRefArgument) { - auto AST = tooling::buildASTFromCode( + auto AST = buildASTFromCode( "void g(int&&); void f() { int x; g(static_cast(x)); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(static_cast(x))")); - AST = tooling::buildASTFromCode( - "void f() { struct A {}; A operator+(A&&, int); " - "A x; static_cast(x) + 1; }"); + AST = buildASTFromCode("struct A {}; A operator+(A&&, int) {}" + "void f() { A x; static_cast(x) + 1; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("static_cast(x) + 1")); - AST = tooling::buildASTFromCode("void f() { struct A { A(int&&); }; " - "int x; A y(static_cast(x)); }"); + AST = buildASTFromCode("void f() { struct A { A(int&&); }; " + "int x; A y(static_cast(x)); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("static_cast(x)")); - AST = tooling::buildASTFromCode("void f() { struct A { A(); A(A&&); }; " - "A x; A y(static_cast(x)); }"); + AST = buildASTFromCode("void f() { struct A { A(); A(A&&); }; " + "A x; A y(static_cast(x)); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("static_cast(x)")); } TEST(ExprMutationAnalyzerTest, ByConstRRefArgument) { - auto AST = tooling::buildASTFromCode( + auto AST = buildASTFromCode( "void g(const int&&); void f() { int x; g(static_cast(x)); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { struct A {}; A operator+(const A&&, int); " - "A x; static_cast(x) + 1; }"); + AST = buildASTFromCode("struct A {}; A operator+(const A&&, int) {}" + "void f() { A x; static_cast(x) + 1; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("void f() { struct A { A(const int&&); }; " - "int x; A y(static_cast(x)); }"); + AST = buildASTFromCode("void f() { struct A { A(const int&&); }; " + "int x; A y(static_cast(x)); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("void f() { struct A { A(); A(const A&&); }; " - "A x; A y(static_cast(x)); }"); + AST = buildASTFromCode("void f() { struct A { A(); A(const A&&); }; " + "A x; A y(static_cast(x)); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, Move) { - auto AST = - tooling::buildASTFromCode(StdRemoveReference + StdMove + - "void f() { struct A {}; A x; std::move(x); }"); + auto AST = buildASTFromCode(StdRemoveReference + StdMove + + "void f() { struct A {}; A x; std::move(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - StdRemoveReference + StdMove + - "void f() { struct A {}; A x, y; std::move(x) = y; }"); + AST = buildASTFromCode(StdRemoveReference + StdMove + + "void f() { struct A {}; A x, y; std::move(x) = y; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("std::move(x) = y")); - AST = tooling::buildASTFromCode(StdRemoveReference + StdMove + - "void f() { int x, y; y = std::move(x); }"); + AST = buildASTFromCode(StdRemoveReference + StdMove + + "void f() { int x, y; y = std::move(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - StdRemoveReference + StdMove + - "struct S { S(); S(const S&); S& operator=(const S&); };" - "void f() { S x, y; y = std::move(x); }"); + AST = + buildASTFromCode(StdRemoveReference + StdMove + + "struct S { S(); S(const S&); S& operator=(const S&); };" + "void f() { S x, y; y = std::move(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = - tooling::buildASTFromCode(StdRemoveReference + StdMove + - "struct S { S(); S(S&&); S& operator=(S&&); };" - "void f() { S x, y; y = std::move(x); }"); + AST = buildASTFromCode(StdRemoveReference + StdMove + + "struct S { S(); S(S&&); S& operator=(S&&); };" + "void f() { S x, y; y = std::move(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("y = std::move(x)")); - AST = - tooling::buildASTFromCode(StdRemoveReference + StdMove + - "struct S { S(); S(const S&); S(S&&);" - "S& operator=(const S&); S& operator=(S&&); };" - "void f() { S x, y; y = std::move(x); }"); + AST = buildASTFromCode(StdRemoveReference + StdMove + + "struct S { S(); S(const S&); S(S&&);" + "S& operator=(const S&); S& operator=(S&&); };" + "void f() { S x, y; y = std::move(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("y = std::move(x)")); - AST = tooling::buildASTFromCode( - StdRemoveReference + StdMove + - "struct S { S(); S(const S&); S(S&&);" - "S& operator=(const S&); S& operator=(S&&); };" - "void f() { const S x; S y; y = std::move(x); }"); + AST = buildASTFromCode(StdRemoveReference + StdMove + + "struct S { S(); S(const S&); S(S&&);" + "S& operator=(const S&); S& operator=(S&&); };" + "void f() { const S x; S y; y = std::move(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode(StdRemoveReference + StdMove + - "struct S { S(); S(S); S& operator=(S); };" - "void f() { S x, y; y = std::move(x); }"); + AST = buildASTFromCode(StdRemoveReference + StdMove + + "struct S { S(); S& operator=(S); };" + "void f() { S x, y; y = std::move(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - StdRemoveReference + StdMove + - "struct S{}; void f() { S x, y; y = std::move(x); }"); + AST = buildASTFromCode(StdRemoveReference + StdMove + + "struct S{}; void f() { S x, y; y = std::move(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("y = std::move(x)")); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( StdRemoveReference + StdMove + "struct S{}; void f() { const S x; S y; y = std::move(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -460,14 +443,14 @@ } TEST(ExprMutationAnalyzerTest, Forward) { - auto AST = tooling::buildASTFromCode( - StdRemoveReference + StdForward + - "void f() { struct A {}; A x; std::forward(x); }"); + auto AST = + buildASTFromCode(StdRemoveReference + StdForward + + "void f() { struct A {}; A x; std::forward(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( StdRemoveReference + StdForward + "void f() { struct A {}; A x, y; std::forward(x) = y; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -476,52 +459,52 @@ } TEST(ExprMutationAnalyzerTest, CallUnresolved) { - auto AST = tooling::buildASTFromCodeWithArgs( - "template void f() { T x; g(x); }", - {"-fno-delayed-template-parsing"}); + auto AST = + buildASTFromCodeWithArgs("template void f() { T x; g(x); }", + {"-fno-delayed-template-parsing"}); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = tooling::buildASTFromCodeWithArgs( - "template void f() { char x[N]; g(x); }", - {"-fno-delayed-template-parsing"}); + AST = + buildASTFromCodeWithArgs("template void f() { char x[N]; g(x); }", + {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "template void f(T t) { int x; g(t, x); }", {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(t, x)")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "template void f(T t) { int x; t.mf(x); }", {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("t.mf(x)")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "template struct S;" "template void f() { S s; int x; s.mf(x); }", {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("s.mf(x)")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "struct S { template void mf(); };" "template void f(S s) { int x; s.mf(x); }", {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("s.mf(x)")); - AST = tooling::buildASTFromCodeWithArgs("template " - "void g(F f) { int x; f(x); } ", - {"-fno-delayed-template-parsing"}); + AST = buildASTFromCodeWithArgs("template " + "void g(F f) { int x; f(x); } ", + {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("f(x)")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "template void f() { int x; (void)T(x); }", {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -529,39 +512,38 @@ } TEST(ExprMutationAnalyzerTest, ReturnAsValue) { - auto AST = tooling::buildASTFromCode("int f() { int x; return x; }"); + auto AST = buildASTFromCode("int f() { int x; return x; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("int* f() { int* x; return x; }"); + AST = buildASTFromCode("int* f() { int* x; return x; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("typedef int* IntPtr;" - "IntPtr f() { int* x; return x; }"); + AST = buildASTFromCode("typedef int* IntPtr;" + "IntPtr f() { int* x; return x; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, ReturnAsNonConstRef) { - const auto AST = tooling::buildASTFromCode("int& f() { int x; return x; }"); + const auto AST = buildASTFromCode("int& f() { int x; return x; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("return x;")); } TEST(ExprMutationAnalyzerTest, ReturnAsConstRef) { - const auto AST = - tooling::buildASTFromCode("const int& f() { int x; return x; }"); + const auto AST = buildASTFromCode("const int& f() { int x; return x; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, ReturnAsNonConstRRef) { - const auto AST = tooling::buildASTFromCode( - "int&& f() { int x; return static_cast(x); }"); + const auto AST = + buildASTFromCode("int&& f() { int x; return static_cast(x); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), @@ -569,7 +551,7 @@ } TEST(ExprMutationAnalyzerTest, ReturnAsConstRRef) { - const auto AST = tooling::buildASTFromCode( + const auto AST = buildASTFromCode( "const int&& f() { int x; return static_cast(x); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -577,8 +559,7 @@ } TEST(ExprMutationAnalyzerTest, TakeAddress) { - const auto AST = - tooling::buildASTFromCode("void g(int*); void f() { int x; g(&x); }"); + const auto AST = buildASTFromCode("void g(int*); void f() { int x; g(&x); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("&x")); @@ -586,14 +567,14 @@ TEST(ExprMutationAnalyzerTest, ArrayToPointerDecay) { const auto AST = - tooling::buildASTFromCode("void g(int*); void f() { int x[2]; g(x); }"); + buildASTFromCode("void g(int*); void f() { int x[2]; g(x); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x")); } TEST(ExprMutationAnalyzerTest, TemplateWithArrayToPointerDecay) { - const auto AST = tooling::buildASTFromCodeWithArgs( + const auto AST = buildASTFromCodeWithArgs( "template struct S { static constexpr int v = 8; };" "template <> struct S { static constexpr int v = 4; };" "void g(char*);" @@ -609,7 +590,7 @@ } TEST(ExprMutationAnalyzerTest, FollowRefModified) { - auto AST = tooling::buildASTFromCode( + auto AST = buildASTFromCode( "void f() { int x; int& r0 = x; int& r1 = r0; int& r2 = r1; " "int& r3 = r2; r3 = 10; }"); auto Results = @@ -617,40 +598,37 @@ EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("r0", "r1", "r2", "r3", "r3 = 10")); - AST = tooling::buildASTFromCode( - "typedef int& IntRefX;" - "using IntRefY = int&;" - "void f() { int x; IntRefX r0 = x; IntRefY r1 = r0;" - "decltype((x)) r2 = r1; r2 = 10; }"); + AST = buildASTFromCode("typedef int& IntRefX;" + "using IntRefY = int&;" + "void f() { int x; IntRefX r0 = x; IntRefY r1 = r0;" + "decltype((x)) r2 = r1; r2 = 10; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("r0", "r1", "r2", "r2 = 10")); } TEST(ExprMutationAnalyzerTest, FollowRefNotModified) { - auto AST = tooling::buildASTFromCode( + auto AST = buildASTFromCode( "void f() { int x; int& r0 = x; int& r1 = r0; int& r2 = r1; " "int& r3 = r2; int& r4 = r3; int& r5 = r4;}"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { int x; int& r0 = x; const int& r1 = r0;}"); + AST = buildASTFromCode("void f() { int x; int& r0 = x; const int& r1 = r0;}"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "typedef const int& CIntRefX;" - "using CIntRefY = const int&;" - "void f() { int x; int& r0 = x; CIntRefX r1 = r0;" - "CIntRefY r2 = r1; decltype((r1)) r3 = r2;}"); + AST = buildASTFromCode("typedef const int& CIntRefX;" + "using CIntRefY = const int&;" + "void f() { int x; int& r0 = x; CIntRefX r1 = r0;" + "CIntRefY r2 = r1; decltype((r1)) r3 = r2;}"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, FollowConditionalRefModified) { - const auto AST = tooling::buildASTFromCode( + const auto AST = buildASTFromCode( "void f() { int x, y; bool b; int &r = b ? x : y; r = 10; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -658,29 +636,28 @@ } TEST(ExprMutationAnalyzerTest, FollowConditionalRefNotModified) { - const auto AST = tooling::buildASTFromCode( - "void f() { int x, y; bool b; int& r = b ? x : y; }"); + const auto AST = + buildASTFromCode("void f() { int x, y; bool b; int& r = b ? x : y; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, FollowFuncArgModified) { - auto AST = - tooling::buildASTFromCode("template void g(T&& t) { t = 10; }" - "void f() { int x; g(x); }"); + auto AST = buildASTFromCode("template void g(T&& t) { t = 10; }" + "void f() { int x; g(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "void h(int&);" "template void g(Args&&... args) { h(args...); }" "void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "void h(int&, int);" "template void g(Args&&... args) { h(args...); }" "void f() { int x, y; g(x, y); }"); @@ -689,7 +666,7 @@ Results = match(withEnclosingCompound(declRefTo("y")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "void h(int, int&);" "template void g(Args&&... args) { h(args...); }" "void f() { int x, y; g(y, x); }"); @@ -698,115 +675,108 @@ Results = match(withEnclosingCompound(declRefTo("y")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "struct S { template S(T&& t) { t = 10; } };" - "void f() { int x; S s(x); }"); + AST = buildASTFromCode("struct S { template S(T&& t) { t = 10; } };" + "void f() { int x; S s(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x")); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "struct S { template S(T&& t) : m(++t) { } int m; };" "void f() { int x; S s(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x")); - AST = tooling::buildASTFromCode( - StdRemoveReference + StdForward + - "template void u(Args&...);" - "template void h(Args&&... args)" - "{ u(std::forward(args)...); }" - "template void g(Args&&... args)" - "{ h(std::forward(args)...); }" - "void f() { int x; g(x); }"); + AST = buildASTFromCode(StdRemoveReference + StdForward + + "template void u(Args&...);" + "template void h(Args&&... args)" + "{ u(std::forward(args)...); }" + "template void g(Args&&... args)" + "{ h(std::forward(args)...); }" + "void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("g(x)")); } TEST(ExprMutationAnalyzerTest, FollowFuncArgNotModified) { - auto AST = tooling::buildASTFromCode("template void g(T&&) {}" - "void f() { int x; g(x); }"); + auto AST = buildASTFromCode("template void g(T&&) {}" + "void f() { int x; g(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("template void g(T&& t) { t; }" - "void f() { int x; g(x); }"); + AST = buildASTFromCode("template void g(T&& t) { t; }" + "void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = - tooling::buildASTFromCode("template void g(Args&&...) {}" - "void f() { int x; g(x); }"); + AST = buildASTFromCode("template void g(Args&&...) {}" + "void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = - tooling::buildASTFromCode("template void g(Args&&...) {}" - "void f() { int y, x; g(y, x); }"); + AST = buildASTFromCode("template void g(Args&&...) {}" + "void f() { int y, x; g(y, x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "void h(int, int&);" "template void g(Args&&... args) { h(args...); }" "void f() { int x, y; g(x, y); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "struct S { template S(T&& t) { t; } };" - "void f() { int x; S s(x); }"); + AST = buildASTFromCode("struct S { template S(T&& t) { t; } };" + "void f() { int x; S s(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "struct S { template S(T&& t) : m(t) { } int m; };" "void f() { int x; S s(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - StdRemoveReference + StdForward + - "template void u(Args...);" - "template void h(Args&&... args)" - "{ u(std::forward(args)...); }" - "template void g(Args&&... args)" - "{ h(std::forward(args)...); }" - "void f() { int x; g(x); }"); + AST = buildASTFromCode(StdRemoveReference + StdForward + + "template void u(Args...);" + "template void h(Args&&... args)" + "{ u(std::forward(args)...); }" + "template void g(Args&&... args)" + "{ h(std::forward(args)...); }" + "void f() { int x; g(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, ArrayElementModified) { - const auto AST = - tooling::buildASTFromCode("void f() { int x[2]; x[0] = 10; }"); + const auto AST = buildASTFromCode("void f() { int x[2]; x[0] = 10; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x[0] = 10")); } TEST(ExprMutationAnalyzerTest, ArrayElementNotModified) { - const auto AST = tooling::buildASTFromCode("void f() { int x[2]; x[0]; }"); + const auto AST = buildASTFromCode("void f() { int x[2]; x[0]; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, NestedMemberModified) { - auto AST = tooling::buildASTFromCode( - "void f() { struct A { int vi; }; struct B { A va; }; " - "struct C { B vb; }; C x; x.vb.va.vi = 10; }"); + auto AST = + buildASTFromCode("void f() { struct A { int vi; }; struct B { A va; }; " + "struct C { B vb; }; C x; x.vb.va.vi = 10; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.vb.va.vi = 10")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "template void f() { T x; x.y.z = 10; }", {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x.y.z = 10")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "template struct S;" "template void f() { S x; x.y.z = 10; }", {"-fno-delayed-template-parsing"}); @@ -815,46 +785,44 @@ } TEST(ExprMutationAnalyzerTest, NestedMemberNotModified) { - auto AST = tooling::buildASTFromCode( - "void f() { struct A { int vi; }; struct B { A va; }; " - "struct C { B vb; }; C x; x.vb.va.vi; }"); + auto AST = + buildASTFromCode("void f() { struct A { int vi; }; struct B { A va; }; " + "struct C { B vb; }; C x; x.vb.va.vi; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCodeWithArgs( - "template void f() { T x; x.y.z; }", - {"-fno-delayed-template-parsing"}); + AST = buildASTFromCodeWithArgs("template void f() { T x; x.y.z; }", + {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCodeWithArgs( - "template struct S;" - "template void f() { S x; x.y.z; }", - {"-fno-delayed-template-parsing"}); + AST = + buildASTFromCodeWithArgs("template struct S;" + "template void f() { S x; x.y.z; }", + {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, CastToValue) { const auto AST = - tooling::buildASTFromCode("void f() { int x; static_cast(x); }"); + buildASTFromCode("void f() { int x; static_cast(x); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, CastToRefModified) { - auto AST = tooling::buildASTFromCode( - "void f() { int x; static_cast(x) = 10; }"); + auto AST = + buildASTFromCode("void f() { int x; static_cast(x) = 10; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("static_cast(x) = 10")); - AST = tooling::buildASTFromCode( - "typedef int& IntRef;" - "void f() { int x; static_cast(x) = 10; }"); + AST = buildASTFromCode("typedef int& IntRef;" + "void f() { int x; static_cast(x) = 10; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("static_cast(x) = 10")); @@ -862,45 +830,41 @@ TEST(ExprMutationAnalyzerTest, CastToRefNotModified) { const auto AST = - tooling::buildASTFromCode("void f() { int x; static_cast(x); }"); + buildASTFromCode("void f() { int x; static_cast(x); }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, CastToConstRef) { - auto AST = tooling::buildASTFromCode( - "void f() { int x; static_cast(x); }"); + auto AST = + buildASTFromCode("void f() { int x; static_cast(x); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = - tooling::buildASTFromCode("typedef const int& CIntRef;" - "void f() { int x; static_cast(x); }"); + AST = buildASTFromCode("typedef const int& CIntRef;" + "void f() { int x; static_cast(x); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, LambdaDefaultCaptureByValue) { - const auto AST = - tooling::buildASTFromCode("void f() { int x; [=]() { x = 10; }; }"); + const auto AST = buildASTFromCode("void f() { int x; [=]() { x; }; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, LambdaExplicitCaptureByValue) { - const auto AST = - tooling::buildASTFromCode("void f() { int x; [x]() { x = 10; }; }"); + const auto AST = buildASTFromCode("void f() { int x; [x]() { x; }; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, LambdaDefaultCaptureByRef) { - const auto AST = - tooling::buildASTFromCode("void f() { int x; [&]() { x = 10; }; }"); + const auto AST = buildASTFromCode("void f() { int x; [&]() { x = 10; }; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), @@ -908,8 +872,7 @@ } TEST(ExprMutationAnalyzerTest, LambdaExplicitCaptureByRef) { - const auto AST = - tooling::buildASTFromCode("void f() { int x; [&x]() { x = 10; }; }"); + const auto AST = buildASTFromCode("void f() { int x; [&x]() { x = 10; }; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), @@ -917,40 +880,38 @@ } TEST(ExprMutationAnalyzerTest, RangeForArrayByRefModified) { - auto AST = tooling::buildASTFromCode( - "void f() { int x[2]; for (int& e : x) e = 10; }"); + auto AST = + buildASTFromCode("void f() { int x[2]; for (int& e : x) e = 10; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("e", "e = 10")); - AST = tooling::buildASTFromCode( - "typedef int& IntRef;" - "void f() { int x[2]; for (IntRef e : x) e = 10; }"); + AST = buildASTFromCode("typedef int& IntRef;" + "void f() { int x[2]; for (IntRef e : x) e = 10; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("e", "e = 10")); } TEST(ExprMutationAnalyzerTest, RangeForArrayByRefNotModified) { const auto AST = - tooling::buildASTFromCode("void f() { int x[2]; for (int& e : x) e; }"); + buildASTFromCode("void f() { int x[2]; for (int& e : x) e; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, RangeForArrayByValue) { - auto AST = tooling::buildASTFromCode( - "void f() { int x[2]; for (int e : x) e = 10; }"); + auto AST = buildASTFromCode("void f() { int x[2]; for (int e : x) e = 10; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { int* x[2]; for (int* e : x) e = nullptr; }"); + AST = + buildASTFromCode("void f() { int* x[2]; for (int* e : x) e = nullptr; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "typedef int* IntPtr;" "void f() { int* x[2]; for (IntPtr e : x) e = nullptr; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); @@ -958,39 +919,37 @@ } TEST(ExprMutationAnalyzerTest, RangeForArrayByConstRef) { - auto AST = tooling::buildASTFromCode( - "void f() { int x[2]; for (const int& e : x) e; }"); + auto AST = + buildASTFromCode("void f() { int x[2]; for (const int& e : x) e; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "typedef const int& CIntRef;" - "void f() { int x[2]; for (CIntRef e : x) e; }"); + AST = buildASTFromCode("typedef const int& CIntRef;" + "void f() { int x[2]; for (CIntRef e : x) e; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, RangeForNonArrayByRefModified) { const auto AST = - tooling::buildASTFromCode("struct V { int* begin(); int* end(); };" - "void f() { V x; for (int& e : x) e = 10; }"); + buildASTFromCode("struct V { int* begin(); int* end(); };" + "void f() { V x; for (int& e : x) e = 10; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("e", "e = 10")); } TEST(ExprMutationAnalyzerTest, RangeForNonArrayByRefNotModified) { - const auto AST = - tooling::buildASTFromCode("struct V { int* begin(); int* end(); };" - "void f() { V x; for (int& e : x) e; }"); + const auto AST = buildASTFromCode("struct V { int* begin(); int* end(); };" + "void f() { V x; for (int& e : x) e; }"); const auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, RangeForNonArrayByValue) { - const auto AST = tooling::buildASTFromCode( + const auto AST = buildASTFromCode( "struct V { const int* begin() const; const int* end() const; };" "void f() { V x; for (int e : x) e; }"); const auto Results = @@ -999,7 +958,7 @@ } TEST(ExprMutationAnalyzerTest, RangeForNonArrayByConstRef) { - const auto AST = tooling::buildASTFromCode( + const auto AST = buildASTFromCode( "struct V { const int* begin() const; const int* end() const; };" "void f() { V x; for (const int& e : x) e; }"); const auto Results = @@ -1008,53 +967,50 @@ } TEST(ExprMutationAnalyzerTest, UnevaluatedExpressions) { - auto AST = tooling::buildASTFromCode( - "void f() { int x, y; decltype(x = 10) z = y; }"); + auto AST = buildASTFromCode("void f() { int x, y; decltype(x = 10) z = y; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { int x, y; __typeof(x = 10) z = y; }"); + AST = buildASTFromCode("void f() { int x, y; __typeof(x = 10) z = y; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( - "void f() { int x, y; __typeof__(x = 10) z = y; }"); + AST = buildASTFromCode("void f() { int x, y; __typeof__(x = 10) z = y; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("void f() { int x; sizeof(x = 10); }"); + AST = buildASTFromCode("void f() { int x; sizeof(x = 10); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("void f() { int x; alignof(x = 10); }"); + AST = buildASTFromCode("void f() { int x; alignof(x = 10); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode("void f() { int x; noexcept(x = 10); }"); + AST = buildASTFromCode("void f() { int x; noexcept(x = 10); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCodeWithArgs("namespace std { class type_info; }" - "void f() { int x; typeid(x = 10); }", - {"-frtti"}); + AST = buildASTFromCodeWithArgs("namespace std { class type_info; }" + "void f() { int x; typeid(x = 10); }", + {"-frtti"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode( + AST = buildASTFromCode( "void f() { int x; _Generic(x = 10, int: 0, default: 1); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); } TEST(ExprMutationAnalyzerTest, NotUnevaluatedExpressions) { - auto AST = tooling::buildASTFromCode("void f() { int x; sizeof(int[x++]); }"); + auto AST = buildASTFromCode("void f() { int x; sizeof(int[x++]); }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x++")); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( "namespace std { class type_info; }" "struct A { virtual ~A(); }; struct B : A {};" "struct X { A& f(); }; void f() { X x; typeid(x.f()); }", @@ -1075,47 +1031,45 @@ " T* operator->() const;" "};"; - auto AST = tooling::buildASTFromCode( - UniquePtrDef + "void f() { UniquePtr x; *x = 10; }"); + auto AST = buildASTFromCode(UniquePtrDef + + "void f() { UniquePtr x; *x = 10; }"); auto Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("* x = 10")); - AST = tooling::buildASTFromCode(UniquePtrDef + - "void f() { UniquePtr x; *x; }"); + AST = buildASTFromCode(UniquePtrDef + "void f() { UniquePtr x; *x; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode(UniquePtrDef + - "void f() { UniquePtr x; *x; }"); + AST = buildASTFromCode(UniquePtrDef + + "void f() { UniquePtr x; *x; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode(UniquePtrDef + - "struct S { int v; };" - "void f() { UniquePtr x; x->v; }"); + AST = buildASTFromCode(UniquePtrDef + "struct S { int v; };" + "void f() { UniquePtr x; x->v; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x")); - AST = tooling::buildASTFromCode(UniquePtrDef + - "struct S { int v; };" - "void f() { UniquePtr x; x->v; }"); + AST = buildASTFromCode(UniquePtrDef + + "struct S { int v; };" + "void f() { UniquePtr x; x->v; }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCode(UniquePtrDef + - "struct S { void mf(); };" - "void f() { UniquePtr x; x->mf(); }"); + AST = + buildASTFromCode(UniquePtrDef + "struct S { void mf(); };" + "void f() { UniquePtr x; x->mf(); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_THAT(mutatedBy(Results, AST.get()), ElementsAre("x")); - AST = tooling::buildASTFromCode( - UniquePtrDef + "struct S { void mf() const; };" - "void f() { UniquePtr x; x->mf(); }"); + AST = buildASTFromCode(UniquePtrDef + + "struct S { void mf() const; };" + "void f() { UniquePtr x; x->mf(); }"); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext()); EXPECT_FALSE(isMutated(Results, AST.get())); - AST = tooling::buildASTFromCodeWithArgs( + AST = buildASTFromCodeWithArgs( UniquePtrDef + "template void f() { UniquePtr x; x->mf(); }", {"-fno-delayed-template-parsing"}); Results = match(withEnclosingCompound(declRefTo("x")), AST->getASTContext());