| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #include "TestVisitor.h" |
| 10 | |
| 11 | using namespace clang; |
| 12 | |
| 13 | namespace { |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | class ConstructExprVisitor |
| 22 | : public ExpectedLocationVisitor<ConstructExprVisitor> { |
| 23 | public: |
| 24 | ConstructExprVisitor() : ShouldVisitImplicitCode(false) {} |
| 25 | |
| 26 | bool shouldVisitImplicitCode() const { return ShouldVisitImplicitCode; } |
| 27 | |
| 28 | void setShouldVisitImplicitCode(bool NewValue) { |
| 29 | ShouldVisitImplicitCode = NewValue; |
| 30 | } |
| 31 | |
| 32 | bool VisitCXXConstructExpr(CXXConstructExpr* Expr) { |
| 33 | if (const CXXConstructorDecl* Ctor = Expr->getConstructor()) { |
| 34 | if (const CXXRecordDecl* Class = Ctor->getParent()) { |
| 35 | Match(Class->getName(), Expr->getLocation()); |
| 36 | } |
| 37 | } |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | bool ShouldVisitImplicitCode; |
| 43 | }; |
| 44 | |
| 45 | TEST(RecursiveASTVisitor, CanVisitImplicitMemberInitializations) { |
| 46 | ConstructExprVisitor Visitor; |
| 47 | Visitor.setShouldVisitImplicitCode(true); |
| 48 | Visitor.ExpectMatch("WithCtor", 2, 8); |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | EXPECT_TRUE(Visitor.runOver( |
| 54 | "struct WithCtor { WithCtor(); }; \n" |
| 55 | "struct Simple { WithCtor w; }; \n" |
| 56 | "int main() { Simple s; }\n")); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | |
| 61 | TEST(RecursiveASTVisitor, CanSkipImplicitMemberInitializations) { |
| 62 | ConstructExprVisitor Visitor; |
| 63 | Visitor.setShouldVisitImplicitCode(false); |
| 64 | Visitor.DisallowMatch("WithCtor", 2, 8); |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | EXPECT_TRUE(Visitor.runOver( |
| 70 | "struct WithCtor { WithCtor(); }; \n" |
| 71 | "struct Simple { WithCtor w; }; \n" |
| 72 | "int main() { Simple s; }\n")); |
| 73 | } |
| 74 | |
| 75 | } |
| 76 | |