From 0d9a2b2205dd65230aabc2fb1a83ed2ae8ec07f2 Mon Sep 17 00:00:00 2001 From: Joey Gouly Date: Fri, 16 May 2014 19:31:08 +0000 Subject: [PATCH] [ASTMatchers] Move the 'isImplicit' matcher from CXXConstructorDecl to Decl. llvm-svn: 209006 --- clang/include/clang/ASTMatchers/ASTMatchers.h | 12 ++++++------ clang/unittests/ASTMatchers/ASTMatchersTest.cpp | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h index 81fa3d49fb5c..e7d5e5f1a14f 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchers.h +++ b/clang/include/clang/ASTMatchers/ASTMatchers.h @@ -311,6 +311,12 @@ AST_MATCHER(Decl, isPrivate) { return Node.getAccess() == AS_private; } +/// \brief Matches a declaration that has been implicitly added +/// by the compiler (eg. implicit default/copy constructors). +AST_MATCHER(Decl, isImplicit) { + return Node.isImplicit(); +} + /// \brief Matches classTemplateSpecializations that have at least one /// TemplateArgument matching the given InnerMatcher. /// @@ -2187,12 +2193,6 @@ AST_MATCHER(CXXCtorInitializer, isWritten) { return Node.isWritten(); } -/// \brief Matches a constructor declaration that has been implicitly added -/// by the compiler (eg. implicit default/copy constructors). -AST_MATCHER(CXXConstructorDecl, isImplicit) { - return Node.isImplicit(); -} - /// \brief Matches any argument of a call expression or a constructor call /// expression. /// diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp index 5d09700e6e0e..e7d99242fcf0 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -1773,6 +1773,9 @@ TEST(ConstructorDeclaration, IsImplicit) { constructorDecl(isImplicit()))); EXPECT_TRUE(matches("class Foo { Foo(){} };", constructorDecl(unless(isImplicit())))); + // The compiler added an implicit assignment operator. + EXPECT_TRUE(matches("struct A { int x; } a = {0}, b = a; void f() { a = b; }", + methodDecl(isImplicit(), hasName("operator=")))); } TEST(DestructorDeclaration, MatchesVirtualDestructor) {