diff --git a/compilerplugins/clang/check.cxx b/compilerplugins/clang/check.cxx index acda74adacd6dd0999f6da356d04aa22a5cabcac..f2443e44a1f2a193d3f1b31ba8cb8856ff9b9d1c 100644 --- a/compilerplugins/clang/check.cxx +++ b/compilerplugins/clang/check.cxx @@ -280,6 +280,35 @@ bool isOkToRemoveArithmeticCast( return true; } + +static bool BaseCheckNotSubclass(const clang::CXXRecordDecl *BaseDefinition, void *p) { + if (!BaseDefinition) + return true; + auto const & base = *static_cast(p); + if (base(BaseDefinition)) { + return false; + } + return true; +} + +bool isDerivedFrom(const clang::CXXRecordDecl *decl, DeclChecker base) { + if (!decl) + return false; + if (base(decl)) + return true; + if (!decl->hasDefinition()) { + return false; + } + if (!decl->forallBases( + [&base](const clang::CXXRecordDecl *BaseDefinition) -> bool + { return BaseCheckNotSubclass(BaseDefinition, &base); }, + true)) + { + return true; + } + return false; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/compilerplugins/clang/check.hxx b/compilerplugins/clang/check.hxx index 4ae65f139955621627d3f9ded3438cba3c6f2f15..0d636636a81ad53500bf205455d33bd960070881 100644 --- a/compilerplugins/clang/check.hxx +++ b/compilerplugins/clang/check.hxx @@ -140,6 +140,12 @@ private: bool const satisfied_; }; + +typedef std::function DeclChecker; +// Returns true if the class has a base matching the checker, or if the class itself matches. +bool isDerivedFrom(const clang::CXXRecordDecl *decl, DeclChecker base); + + namespace detail { ContextCheck checkRecordDecl( diff --git a/compilerplugins/clang/refcounting.cxx b/compilerplugins/clang/refcounting.cxx index 6ae861cfcad99387bb22048766a21335e5ada342..535808a3a0caf8065570b40661ab290d329ddf0f 100644 --- a/compilerplugins/clang/refcounting.cxx +++ b/compilerplugins/clang/refcounting.cxx @@ -35,7 +35,7 @@ not delete on last 'release'. */ -namespace { +namespace loplugin { class RefCounting: public loplugin::FilteringPlugin @@ -72,37 +72,6 @@ private: bool visitTemporaryObjectExpr(Expr const * expr); }; -typedef std::function DeclChecker; - -bool BaseCheckNotSubclass(const CXXRecordDecl *BaseDefinition, void *p) { - if (!BaseDefinition) - return true; - auto const & base = *static_cast(p); - if (base(BaseDefinition)) { - return false; - } - return true; -} - -bool isDerivedFrom(const CXXRecordDecl *decl, DeclChecker base) { - if (!decl) - return false; - if (base(decl)) - return true; - if (!decl->hasDefinition()) { - return false; - } - if (!decl->forallBases( - [&base](const CXXRecordDecl *BaseDefinition) -> bool - { return BaseCheckNotSubclass(BaseDefinition, &base); }, - true)) - { - return true; - } - return false; -} - - bool containsXInterfaceSubclass(const clang::Type* pType0); bool containsXInterfaceSubclass(const QualType& qType) {