summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/test/unreffun.cxx25
-rw-r--r--compilerplugins/clang/test/unreffun.hxx17
-rw-r--r--compilerplugins/clang/unreffun.cxx18
3 files changed, 60 insertions, 0 deletions
diff --git a/compilerplugins/clang/test/unreffun.cxx b/compilerplugins/clang/test/unreffun.cxx
new file mode 100644
index 000000000000..d9d56afe3c35
--- /dev/null
+++ b/compilerplugins/clang/test/unreffun.cxx
@@ -0,0 +1,25 @@
+/* -*- 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: */
diff --git a/compilerplugins/clang/test/unreffun.hxx b/compilerplugins/clang/test/unreffun.hxx
new file mode 100644
index 000000000000..20d0e50056be
--- /dev/null
+++ b/compilerplugins/clang/test/unreffun.hxx
@@ -0,0 +1,17 @@
+/* -*- 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: */
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()))