summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-06-05 16:18:26 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-06-05 16:18:26 +0000
commitb34dc87826de1ebf7fc2cc01e9484835710fe86b (patch)
tree78d45eb8f84c54efac2e39ae585465c64da26426 /clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
parent5bbf8290a790497a571f4717b1f18d1088fd61c3 (diff)
downloadbcm5719-llvm-b34dc87826de1ebf7fc2cc01e9484835710fe86b.tar.gz
bcm5719-llvm-b34dc87826de1ebf7fc2cc01e9484835710fe86b.zip
RecursiveASTVisitor: add ability to visit implicit declarations. Patch by
James Dennett! llvm-svn: 158002
Diffstat (limited to 'clang/unittests/Tooling/RecursiveASTVisitorTest.cpp')
-rw-r--r--clang/unittests/Tooling/RecursiveASTVisitorTest.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
index 9ad825f8cf2..52b3987bc84 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -448,4 +448,31 @@ TEST(RecursiveASTVisitor, VisitsClassTemplateTemplateParmDefaultArgument) {
"template<template <typename> class T> class Y {};\n"));
}
+// A visitor that visits implicit declarations and matches constructors.
+class ImplicitCtorVisitor
+ : public ExpectedLocationVisitor<ImplicitCtorVisitor> {
+public:
+ bool shouldVisitImplicitDeclarations() const { return true; }
+
+ bool VisitCXXConstructorDecl(CXXConstructorDecl* Ctor) {
+ if (Ctor->isImplicit()) { // Was not written in source code
+ if (const CXXRecordDecl* Class = Ctor->getParent()) {
+ Match(Class->getName(), Ctor->getLocation());
+ }
+ }
+ return true;
+ }
+};
+
+TEST(RecursiveASTVisitor, VisitsImplicitCopyConstructors) {
+ ImplicitCtorVisitor Visitor;
+ Visitor.ExpectMatch("Simple", 2, 8);
+ // Note: Clang lazily instantiates implicit declarations, so we need
+ // to use them in order to force them to appear in the AST.
+ EXPECT_TRUE(Visitor.runOver(
+ "struct WithCtor { WithCtor(); }; \n"
+ "struct Simple { Simple(); WithCtor w; }; \n"
+ "int main() { Simple s; Simple t(s); }\n"));
+}
+
} // end namespace clang
OpenPOWER on IntegriCloud