Kaydet (Commit) e1ab0444 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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/55189Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 29dbb864
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "unreffun.hxx"
template <typename> struct S
{
friend void f();
};
void f() {}
void g(); // expected-error {{Unreferenced function declaration [loplugin:unreffun]}}
void h() // expected-error {{Unreferenced externally visible function definition [loplugin:unreffun]}}
{
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_COMPILERPLUGINS_CLANG_TEST_UNREFFUN_HXX
#define INCLUDED_COMPILERPLUGINS_CLANG_TEST_UNREFFUN_HXX
void f();
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
......@@ -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()))
......
......@@ -53,6 +53,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/unnecessaryoverride-dtor \
compilerplugins/clang/test/unnecessaryparen \
compilerplugins/clang/test/unoany \
compilerplugins/clang/test/unreffun \
compilerplugins/clang/test/unusedindex \
compilerplugins/clang/test/unusedvariablecheck \
compilerplugins/clang/test/unusedvariablemore \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment