From: Daniel Jasper Date: Thu, 20 Sep 2012 09:24:58 +0000 (+0000) Subject: Provide better error messages for incorrect matchers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3278162bd6d34783607d4bfe8814df73e8ef8c1;p=clang Provide better error messages for incorrect matchers. By changing the conversion operator into a conversion constructor, we can enabled based on the template parameters leading to better error messages. E.g.: stmt(decl()) will now create an error message including: note: candidate function not viable: no known conversion from 'clang::ast_matchers::internal::BindableMatcher' to 'const clang::ast_matchers::internal::Matcher' for 1st argument git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164298 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/ASTMatchers/ASTMatchersInternal.h b/include/clang/ASTMatchers/ASTMatchersInternal.h index 38ffb2de75..41b56418de 100644 --- a/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -257,6 +257,16 @@ public: explicit Matcher(MatcherInterface *Implementation) : Implementation(Implementation) {} + /// \brief Implicitly converts \c Other to a Matcher. + /// + /// Requires \c T to be derived from \c From. + template + Matcher(const Matcher &Other, + typename llvm::enable_if_c< + llvm::is_base_of::value && + !llvm::is_same::value >::type* = 0) + : Implementation(new ImplicitCastMatcher(Other)) {} + /// \brief Forwards the call to the underlying MatcherInterface pointer. bool matches(const T &Node, ASTMatchFinder *Finder, @@ -264,14 +274,6 @@ public: return Implementation->matches(Node, Finder, Builder); } - /// \brief Implicitly converts this object to a Matcher. - /// - /// Requires Derived to be derived from T. - template - operator Matcher() const { - return Matcher(new ImplicitCastMatcher(*this)); - } - /// \brief Returns an ID that uniquely identifies the matcher. uint64_t getID() const { /// FIXME: Document the requirements this imposes on matcher @@ -289,22 +291,22 @@ public: } private: - /// \brief Allows conversion from Matcher to Matcher if Derived - /// is derived from T. - template - class ImplicitCastMatcher : public MatcherInterface { + /// \brief Allows conversion from Matcher to Matcher if T + /// is derived from Base. + template + class ImplicitCastMatcher : public MatcherInterface { public: - explicit ImplicitCastMatcher(const Matcher &From) + explicit ImplicitCastMatcher(const Matcher &From) : From(From) {} - virtual bool matches(const Derived &Node, + virtual bool matches(const T &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder) const { return From.matches(Node, Finder, Builder); } private: - const Matcher From; + const Matcher From; }; llvm::IntrusiveRefCntPtr< MatcherInterface > Implementation;