avoid windres preprocessor quoting-messups with current cygwin
[LibreOffice.git] / compilerplugins / clang / dllprivate.cxx
blobbb4e9c35a26bfdd5cc8b987f046f1c3efd741272
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 RecursiveASTVisitor<DllPrivate>, public loplugin::Plugin
17 public:
18 explicit DllPrivate(loplugin::InstantiationData const & data): Plugin(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: */