From e1ab04440195092aa0bfbf445e97530082843569 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 1 Jun 2018 16:22:53 +0200 Subject: Improve loplugin:unreffun ...to avoid a false positive in --enable-qt5 > [build CXX] vcl/qt5/Qt5Widget.cxx > /home/sbergman/lo/core/vcl/qt5/Qt5Widget.cxx:466:21: error: Unreferenced function declaration [loplugin:unreffun] > friend QWidget* createQt5Widget(Qt5Frame& rFrame, QWidget* parent, Qt::WindowFlags f); > ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 1 error generated. Change-Id: I01e47bc5f5147916737d62fe18ce5312a0221a3f Reviewed-on: https://gerrit.libreoffice.org/55189 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- compilerplugins/clang/unreffun.cxx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'compilerplugins/clang/unreffun.cxx') 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(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(decl->getLexicalDeclContext())) { + if (lex->isDependentContext()) { + return true; + } + } + } if (!(decl->isThisDeclarationADefinition() || isFriendDecl(decl) || decl->isFunctionTemplateSpecialization())) -- cgit