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/.
15 // Look for places calling std::find on a standard container where it should be using the container find method, which
18 // This lives in /store because the implementation is a hack and is highly dependent on the inwards
19 // of the libc++ library on the machine it runs on.
24 class FindOnContainer
:
25 public RecursiveASTVisitor
<FindOnContainer
>, public loplugin::Plugin
28 explicit FindOnContainer(InstantiationData
const & data
): Plugin(data
) {}
30 virtual void run() override
{ TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl()); }
32 bool VisitCallExpr(const CallExpr
* expr
);
35 bool FindOnContainer::VisitCallExpr(const CallExpr
* expr
) {
36 if (ignoreLocation(expr
)) {
39 FunctionDecl
const * fdecl
= expr
->getDirectCallee();
40 if (fdecl
== nullptr) {
43 std::string qname
{ fdecl
->getQualifiedNameAsString() };
44 if (qname
== "std::find")
46 std::string tname
= expr
->getArg(0)->getType().getAsString();
47 if (tname
.find("std::_List_iterator") != std::string::npos
48 || tname
.find("std::_List_const_iterator") != std::string::npos
49 || tname
.find("std::vector") != std::string::npos
50 || tname
.find("std::_Deque_iterator") != std::string::npos
51 || tname
== "const int *"
52 || tname
== "struct std::_Bit_const_iterator"
53 || tname
== "const rtl::OUString *"
54 || tname
== "class rtl::OUString *"
55 || tname
== "const class rtl::OUString *"
56 || tname
== "const sal_Int8 *"
57 || tname
== "const sal_Int32 *"
58 || tname
== "sal_Int32 *"
59 || tname
== "sal_uInt16 *" )
65 DiagnosticsEngine::Warning
,
66 ("rather use the more specific find method " + tname
),
73 loplugin::Plugin::Registration
< FindOnContainer
> X("findoncontainer");
77 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */