bump product version to 6.3.0.0.beta1
[LibreOffice.git] / compilerplugins / clang / dllprivate.cxx
blob8d0f221c327cc6803cd41124d95249f418dbdf5e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "plugin.hxx"
12 namespace {
14 class DllPrivate final:
15 public loplugin::FilteringPlugin<DllPrivate>
17 public:
18 explicit DllPrivate(loplugin::InstantiationData const & data): FilteringPlugin(data)
21 bool VisitNamedDecl(NamedDecl const * decl) {
22 if (!decl->getLocation().isInvalid()&&ignoreLocation(decl)) {
23 return true;
25 auto a = decl->getAttr<VisibilityAttr>();
26 if (a == nullptr || a->getVisibility() != VisibilityAttr::Hidden) {
27 return true;
29 if (compiler.getSourceManager().isMacroBodyExpansion(
30 decl->getLocation())
31 && (Lexer::getImmediateMacroName(
32 decl->getLocation(), compiler.getSourceManager(),
33 compiler.getLangOpts())
34 == "Q_OBJECT")) // from /usr/include/QtCore/qobjectdefs.h
36 return true;
38 auto p = dyn_cast<RecordDecl>(decl->getDeclContext());
39 if (p == nullptr) {
40 report(
41 DiagnosticsEngine::Warning,
42 "top-level declaration redundantly marked as DLLPRIVATE",
43 a->getLocation())
44 << decl->getSourceRange();
45 } else if (p->getVisibility() == HiddenVisibility) {
46 report(
47 DiagnosticsEngine::Warning,
48 ("declaration nested in DLLPRIVATE declaration redundantly"
49 " marked as DLLPRIVATE"),
50 a->getLocation())
51 << decl->getSourceRange();
52 report(
53 DiagnosticsEngine::Note, "parent declaration is here",
54 p->getLocation())
55 << p->getSourceRange();
57 return true;
60 private:
61 void run() 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 if (!compiler.getPreprocessor().getIdentifierInfo("DISABLE_DYNLOADING")
69 ->hasMacroDefinition())
71 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
76 static loplugin::Plugin::Registration<DllPrivate> reg("dllprivate");
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */