Version 24.2.2.2, tag libreoffice-24.2.2.2
[LibreOffice.git] / compilerplugins / clang / constexprliteral.cxx
blob86bba13e090cad7b6e75eb52efc8eff907caae63
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 #ifndef LO_CLANG_SHARED_PLUGINS
12 #include <cassert>
13 #include <stack>
15 #include "check.hxx"
16 #include "plugin.hxx"
17 #include "config_clang.h"
19 namespace
21 class ConstexprLiteral final : public loplugin::FilteringPlugin<ConstexprLiteral>
23 public:
24 explicit ConstexprLiteral(loplugin::InstantiationData const& data)
25 : FilteringPlugin(data)
29 bool VisitVarDecl(const VarDecl* varDecl)
31 if (ignoreLocation(varDecl))
32 return true;
33 if (varDecl->isConstexpr())
34 return true;
35 if (!loplugin::TypeCheck(varDecl->getType())
36 .Class("OUStringLiteral")
37 .Namespace("rtl")
38 .GlobalNamespace())
39 return true;
40 report(DiagnosticsEngine::Warning, "OUStringLiteral should be declared constexpr",
41 varDecl->getBeginLoc())
42 << varDecl->getSourceRange();
43 return true;
46 bool preRun() override
48 if (!compiler.getLangOpts().CPlusPlus)
49 return false;
50 return true;
53 private:
54 void run() override
56 if (preRun())
58 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
63 loplugin::Plugin::Registration<ConstexprLiteral> constexprliteral("constexprliteral");
66 #endif
68 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */