diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-06-05 16:18:26 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-06-05 16:18:26 +0000 |
commit | c28a335184207a47f34eb9d1707dc8d7c6c7b8b6 (patch) | |
tree | 556292015939d2b128763617dfb73b730e75f4d1 /unittests/Tooling/RecursiveASTVisitorTest.cpp | |
parent | 3dbcc889c1ce291b7aa227597d22c009d5c489e3 (diff) |
RecursiveASTVisitor: add ability to visit implicit declarations. Patch by
James Dennett!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158002 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling/RecursiveASTVisitorTest.cpp')
-rw-r--r-- | unittests/Tooling/RecursiveASTVisitorTest.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/unittests/Tooling/RecursiveASTVisitorTest.cpp b/unittests/Tooling/RecursiveASTVisitorTest.cpp index 9ad825f8cf..52b3987bc8 100644 --- a/unittests/Tooling/RecursiveASTVisitorTest.cpp +++ b/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 |