diff options
Diffstat (limited to 'compilerplugins/clang/unreffun.cxx')
-rw-r--r-- | compilerplugins/clang/unreffun.cxx | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compilerplugins/clang/unreffun.cxx b/compilerplugins/clang/unreffun.cxx index d825423bfeaa..bfd48b328300 100644 --- a/compilerplugins/clang/unreffun.cxx +++ b/compilerplugins/clang/unreffun.cxx @@ -58,7 +58,18 @@ public: void run() override { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); } + bool TraverseFriendDecl(FriendDecl * decl) { + auto const old = friendFunction_; + friendFunction_ = dyn_cast_or_null<FunctionDecl>(decl->getFriendDecl()); + auto const ret = RecursiveASTVisitor::TraverseFriendDecl(decl); + friendFunction_ = old; + return ret; + } + bool VisitFunctionDecl(FunctionDecl const * decl); + +private: + FunctionDecl const * friendFunction_ = nullptr; }; bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) { @@ -74,6 +85,13 @@ bool UnrefFun::VisitFunctionDecl(FunctionDecl const * decl) { { return true; } + if (decl == friendFunction_) { + if (auto const lex = dyn_cast<CXXRecordDecl>(decl->getLexicalDeclContext())) { + if (lex->isDependentContext()) { + return true; + } + } + } if (!(decl->isThisDeclarationADefinition() || isFriendDecl(decl) || decl->isFunctionTemplateSpecialization())) |