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
20 Check for places where we declare a block directly inside a block
25 public loplugin::FilteringPlugin
<BlockBlock
>
28 explicit BlockBlock(loplugin::InstantiationData
const & data
):
29 FilteringPlugin(data
) {}
31 virtual bool preRun() override
33 StringRef
fn(handler
.getMainFileName());
34 if (loplugin::isSamePathname(fn
, SRCDIR
"/sal/osl/unx/file_misc.cxx"))
41 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
45 bool VisitCompoundStmt(CompoundStmt
const * );
48 bool BlockBlock::VisitCompoundStmt(CompoundStmt
const * compound
)
50 if (ignoreLocation(compound
))
52 if (compound
->size() != 1)
54 auto inner
= *compound
->body_begin();
55 if (!isa
<CompoundStmt
>(inner
))
57 if (compiler
.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(compound
)))
59 if (compiler
.getSourceManager().isMacroBodyExpansion(compat::getBeginLoc(inner
)))
61 if (containsPreprocessingConditionalInclusion(compound
->getSourceRange())) {
65 DiagnosticsEngine::Warning
,
66 "block directly inside block",
67 compat::getBeginLoc(compound
))
68 << compound
->getSourceRange();
70 DiagnosticsEngine::Note
,
72 compat::getBeginLoc(inner
))
73 << inner
->getSourceRange();
77 loplugin::Plugin::Registration
< BlockBlock
> blockblock("blockblock", true);
81 #endif // LO_CLANG_SHARED_PLUGINS
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */