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/.
10 #ifndef LO_CLANG_SHARED_PLUGINS
17 // Having an extern prototype for a method in a module and not actually declaring that method is dodgy.
22 class ExternAndNotDefined
:
23 public loplugin::FilteringPlugin
<ExternAndNotDefined
>
26 explicit ExternAndNotDefined(loplugin::InstantiationData
const & data
): FilteringPlugin(data
) {}
28 virtual void run() override
{ TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl()); }
30 bool VisitFunctionDecl(const FunctionDecl
* decl
);
33 bool ExternAndNotDefined::VisitFunctionDecl(const FunctionDecl
* functionDecl
) {
34 if (ignoreLocation(functionDecl
)) {
37 if (functionDecl
->isDefined() || compat::isPureVirtual(functionDecl
)
38 || (functionDecl
->getLinkageAndVisibility().getLinkage()
39 != compat::Linkage::External
)) {
42 //TODO, filtering out anything template for now:
43 if (functionDecl
->isDependentContext()) {
46 CXXRecordDecl
const * r
= dyn_cast
<CXXRecordDecl
>(functionDecl
->getDeclContext());
47 if (r
!= nullptr && r
->getTemplateSpecializationKind() != TSK_Undeclared
) {
50 // this is the bison/flex C API, it has to be defined this way
51 std::string functionName
= functionDecl
->getNameAsString();
52 if (functionName
== "yyerror" || functionName
== "yyparse" || functionName
== "yylex") {
55 // see vcl/unx/gtk/app/gtksys.cxx, typename conflicts prevent using the right include
56 if (functionName
== "gdk_x11_screen_get_screen_number") {
59 if (!compiler
.getSourceManager().isInMainFile(functionDecl
->getLocation()))
64 DiagnosticsEngine::Warning
,
65 "extern prototype in main file without definition",
66 functionDecl
->getLocation())
67 << functionDecl
->getSourceRange();
72 loplugin::Plugin::Registration
< ExternAndNotDefined
> externandnotdefined("externandnotdefined");
76 #endif // LO_CLANG_SHARED_PLUGINS
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */