1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 // Warn about unnamed namespaces nested (directly) within unnamed namespaces. (It can be hard to
16 // keep track whether a certain spot in a source file is already in an unnamed namespace, so it
17 // happens that additions to the source add redundant, nested unnamed namespaces.)
21 class NestedUnnamed
: public loplugin::FilteringPlugin
<NestedUnnamed
>
24 explicit NestedUnnamed(loplugin::InstantiationData
const& data
)
25 : FilteringPlugin(data
)
29 bool preRun() override
{ return compiler
.getLangOpts().CPlusPlus
; }
35 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
39 bool VisitNamespaceDecl(NamespaceDecl
const* decl
)
41 if (ignoreLocation(decl
))
45 if (!decl
->isAnonymousNamespace())
49 NamespaceDecl
const* outer
;
50 for (auto p
= decl
->getLexicalParent();; p
= p
->getLexicalParent())
52 outer
= dyn_cast
<NamespaceDecl
>(p
);
57 if (isa
<TranslationUnitDecl
>(p
))
62 if (!outer
->isAnonymousNamespace())
66 report(DiagnosticsEngine::Warning
, "unnamed namespace directly nested in unnamed namespace",
68 << decl
->getSourceRange();
69 report(DiagnosticsEngine::Note
, "outer namespace declared here", outer
->getLocation())
70 << outer
->getSourceRange();
75 loplugin::Plugin::Registration
<NestedUnnamed
> nestedunnamed("nestedunnamed");
79 #endif // LO_CLANG_SHARED_PLUGINS
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */