1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
14 // Having an extern prototype for a method in a module and not actually declaring that method is dodgy.
19 class ExternAndNotDefined
:
20 public RecursiveASTVisitor
<ExternAndNotDefined
>, public loplugin::Plugin
23 explicit ExternAndNotDefined(loplugin::InstantiationData
const & data
): Plugin(data
) {}
25 virtual void run() override
{ TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl()); }
27 bool VisitFunctionDecl(const FunctionDecl
* decl
);
30 bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl
* functionDecl
) {
31 if (ignoreLocation(functionDecl
)) {
34 if (functionDecl
->isDefined() || functionDecl
->isPure()
35 || (functionDecl
->getLinkageAndVisibility().getLinkage()
36 != ExternalLinkage
)) {
39 //TODO, filtering out anything template for now:
40 if (functionDecl
->isDependentContext()) {
43 CXXRecordDecl
const * r
= dyn_cast
<CXXRecordDecl
>(functionDecl
->getDeclContext());
44 if (r
!= nullptr && r
->getTemplateSpecializationKind() != TSK_Undeclared
) {
47 // this is the bison/flex C API, it has to be defined this way
48 std::string functionName
= functionDecl
->getNameAsString();
49 if (functionName
== "yyerror" || functionName
== "YYWarning" || functionName
== "yyparse" || functionName
== "yylex") {
52 // see vcl/unx/gtk/app/gtksys.cxx, typename conflicts prevent using the right include
53 if (functionName
== "gdk_x11_screen_get_screen_number") {
56 if (!compiler
.getSourceManager().isInMainFile(functionDecl
->getLocation()))
60 StringRef fileName
{ compiler
.getSourceManager().getFilename(functionDecl
->getLocation()) };
61 // the filters use some kind of dynamic loading stunt
62 if (loplugin::hasPathnamePrefix(fileName
, SRCDIR
"/filter/qa/")) {
66 DiagnosticsEngine::Warning
,
67 "extern prototype in main file without definition",
68 functionDecl
->getLocation())
69 << functionDecl
->getSourceRange();
74 loplugin::Plugin::Registration
< ExternAndNotDefined
> X("externandnotdefined");
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */