bump product version to 6.4.0.3
[LibreOffice.git] / compilerplugins / clang / stringbuffer.cxx
blobb68a8ba327009a286f4bd9557862bf87b034b6d2
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 */
9 #ifndef LO_CLANG_SHARED_PLUGINS
11 #include "check.hxx"
12 #include "plugin.hxx"
13 #include <vector>
15 /** Look for appending result of adding OUString/OString to OUStringBuffer
17 namespace
19 class StringBuffer : public loplugin::FilteringPlugin<StringBuffer>
21 public:
22 explicit StringBuffer(loplugin::InstantiationData const& rData)
23 : FilteringPlugin(rData)
27 bool preRun() override
29 StringRef fn(handler.getMainFileName());
30 return !loplugin::hasPathnamePrefix(fn, SRCDIR "/sal/qa/");
33 void run() override
35 if (preRun())
37 TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
41 bool VisitCXXMemberCallExpr(CXXMemberCallExpr const*);
44 bool StringBuffer::VisitCXXMemberCallExpr(CXXMemberCallExpr const* memberCallExpr)
46 if (ignoreLocation(memberCallExpr))
47 return true;
48 if (!loplugin::DeclCheck(memberCallExpr->getRecordDecl())
49 .Class("OUStringBuffer")
50 .Namespace("rtl")
51 .GlobalNamespace())
52 return true;
53 if (!memberCallExpr->getMethodDecl()->getIdentifier())
54 return true;
55 if (memberCallExpr->getMethodDecl()->getName() != "append")
56 return true;
57 auto matTemp = dyn_cast<MaterializeTemporaryExpr>(memberCallExpr->getArg(0));
58 if (!matTemp)
59 return true;
60 if (!isa<CXXOperatorCallExpr>(matTemp->GetTemporaryExpr()))
61 return true;
62 report(DiagnosticsEngine::Warning,
63 "appending added result of OUString to OUStringBuffer, rather do .append(x).append(y)",
64 compat::getBeginLoc(memberCallExpr))
65 << memberCallExpr->getSourceRange();
66 return true;
69 loplugin::Plugin::Registration<StringBuffer> stringbuffer("stringbuffer", false);
71 } // namespace
73 #endif // LO_CLANG_SHARED_PLUGINS
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */