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/.
9 #ifndef LO_CLANG_SHARED_PLUGINS
15 class DllPrivate final
:
16 public loplugin::FilteringPlugin
<DllPrivate
>
19 explicit DllPrivate(loplugin::InstantiationData
const & data
): FilteringPlugin(data
)
22 bool VisitNamedDecl(NamedDecl
const * decl
) {
23 if (!decl
->getLocation().isInvalid()&&ignoreLocation(decl
)) {
26 auto a
= decl
->getAttr
<VisibilityAttr
>();
27 if (a
== nullptr || a
->getVisibility() != VisibilityAttr::Hidden
) {
30 if (compiler
.getSourceManager().isMacroBodyExpansion(
32 && (Lexer::getImmediateMacroName(
33 decl
->getLocation(), compiler
.getSourceManager(),
34 compiler
.getLangOpts())
35 == "Q_OBJECT")) // from /usr/include/QtCore/qobjectdefs.h
39 auto p
= dyn_cast
<RecordDecl
>(decl
->getDeclContext());
42 DiagnosticsEngine::Warning
,
43 "top-level declaration redundantly marked as DLLPRIVATE",
45 << decl
->getSourceRange();
46 } else if (p
->getVisibility() == HiddenVisibility
) {
48 DiagnosticsEngine::Warning
,
49 ("declaration nested in DLLPRIVATE declaration redundantly"
50 " marked as DLLPRIVATE"),
52 << decl
->getSourceRange();
54 DiagnosticsEngine::Note
, "parent declaration is here",
56 << p
->getSourceRange();
61 bool preRun() override
{
62 // DISABLE_DYNLOADING makes SAL_DLLPUBLIC_{EXPORT,IMPORT,TEMPLATE} expand
63 // to visibility("hidden") attributes, which would cause bogus warnings
64 // here (e.g., in UBSan builds that explicitly define DISABLE_DYNLOADING
65 // in jurt/source/pipe/staticsalhack.cxx); alternatively, change
66 // include/sal/types.h to make those SAL_DLLPUBLIC_* expand to nothing
67 // for DISABLE_DYNLOADING:
68 return !compiler
.getPreprocessor().getIdentifierInfo("DISABLE_DYNLOADING")
69 ->hasMacroDefinition();
74 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
79 static loplugin::Plugin::Registration
<DllPrivate
> dllprivate("dllprivate");
83 #endif // LO_CLANG_SHARED_PLUGINS
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */