Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -3767,11 +3767,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -3997,11 +3999,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -4170,6 +4174,30 @@ +
Matches a node if the declaration associated with that node +matches the given matcher. + +The associated declaration is: +- for type nodes, the declaration of the underlying type +- for CallExpr, the declaration of the callee +- for MemberExpr, the declaration of the referenced member +- for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new + +Also usable as Matcher<T> for any T supporting the getDecl() member +function. e.g. various subtypes of clang::Type and various expressions. + +Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, + Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, + Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, + Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, + Matcher<TemplateSpecializationType>, Matcher<TemplateTypeParmType>, + Matcher<TypedefType>, Matcher<UnresolvedUsingType> +
Matches the first method of a class or struct that satisfies InnerMatcher. @@ -4290,11 +4318,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -4417,11 +4447,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -4579,11 +4611,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -4909,11 +4943,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -4931,11 +4967,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -4953,11 +4991,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -5211,11 +5251,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -5281,11 +5323,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -5408,11 +5452,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -5519,11 +5565,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -5561,11 +5609,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -5612,11 +5662,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, @@ -5653,11 +5705,13 @@ - for CallExpr, the declaration of the callee - for MemberExpr, the declaration of the referenced member - for CXXConstructExpr, the declaration of the constructor +- for CXXNewExpr, the declaration of the operator new Also usable as Matcher<T> for any T supporting the getDecl() member function. e.g. various subtypes of clang::Type and various expressions. Usable as: Matcher<CallExpr>, Matcher<CXXConstructExpr>, + Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, Matcher<AddrLabelExpr>, Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, Matcher<TagType>, Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -2450,16 +2450,18 @@ /// - for CallExpr, the declaration of the callee /// - for MemberExpr, the declaration of the referenced member /// - for CXXConstructExpr, the declaration of the constructor +/// - for CXXNewExpr, the declaration of the operator new /// /// Also usable as Matcherfor any T supporting the getDecl() member /// function. e.g. various subtypes of clang::Type and various expressions. /// -/// Usable as: Matcher , Matcher , -/// Matcher , Matcher , Matcher , -/// Matcher , Matcher , Matcher , -/// Matcher , Matcher , Matcher , -/// Matcher , Matcher , -/// Matcher , Matcher +/// Usable as: Matcher , Matcher , +/// Matcher , Matcher , Matcher , +/// Matcher , Matcher , Matcher , +/// Matcher , Matcher , Matcher , +/// Matcher , Matcher , +/// Matcher , Matcher , +/// Matcher inline internal::PolymorphicMatcherWithParam1< internal::HasDeclarationMatcher, internal::Matcher , void(internal::HasDeclarationSupportedTypes)> Index: include/clang/ASTMatchers/ASTMatchersInternal.h =================================================================== --- include/clang/ASTMatchers/ASTMatchersInternal.h +++ include/clang/ASTMatchers/ASTMatchersInternal.h @@ -787,6 +787,14 @@ return matchesDecl(Node.getConstructor(), Finder, Builder); } + /// \brief Extracts the operator new of the new call and returns whether the + /// inner matcher matches on it. + bool matchesSpecialized(const CXXNewExpr &Node, + ASTMatchFinder *Finder, + BoundNodesTreeBuilder *Builder) const { + return matchesDecl(Node.getOperatorNew(), Finder, Builder); + } + /// \brief Extracts the \c ValueDecl a \c MemberExpr refers to and returns /// whether the inner matcher matches on it. bool matchesSpecialized(const MemberExpr &Node, @@ -1007,11 +1015,11 @@ TypeLoc, QualType> AdaptativeDefaultToTypes; /// \brief All types that are supported by HasDeclarationMatcher above. -typedef TypeList HasDeclarationSupportedTypes; + TemplateTypeParmType, TypedefType, UnresolvedUsingType> + HasDeclarationSupportedTypes; /// \brief Converts a \c Matcher to a matcher of desired type \c To by /// "adapting" a \c To into a \c T. Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -241,6 +241,12 @@ hasDeclaration(namedDecl(hasName("A")))))))); } +TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) { + EXPECT_TRUE( + matches("int *A = new int();", + cxxNewExpr(hasDeclaration(functionDecl(parameterCountIs(1)))))); +} + TEST(HasUnderlyingDecl, Matches) { EXPECT_TRUE(matches("namespace N { template void f(T t); }" "template void g() { using N::f; f(T()); }",