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/.
21 Check for calls to operator== on a std::container< std::unique_ptr >, which is not useful,
22 because std::container will compare the pointers so it is never true
28 public loplugin::FilteringPlugin
<PtrVector
>
31 explicit PtrVector(loplugin::InstantiationData
const & data
): FilteringPlugin(data
)
34 virtual void run() override
36 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
39 bool shouldVisitTemplateInstantiations () const { return true; }
41 bool VisitCXXOperatorCallExpr(const CXXOperatorCallExpr
* );
44 bool PtrVector::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr
* expr
)
46 if (ignoreLocation(expr
)) {
49 if (expr
->getOperator() != clang::OverloadedOperatorKind::OO_EqualEqual
50 && expr
->getOperator() != clang::OverloadedOperatorKind::OO_ExclaimEqual
)
54 if (isa
<CXXNullPtrLiteralExpr
>(expr
->getArg(1))) {
57 const Expr
* argExpr
= expr
->getArg(0);
58 std::string s
= argExpr
->getType().getDesugaredType(compiler
.getASTContext()).getAsString();
59 if (s
.find("iterator") != std::string::npos
60 || (loplugin::TypeCheck(argExpr
->getType()).Class("__wrap_iter").Namespace("__1")
65 if (s
.find("array") == std::string::npos
&& s
.find("deque") == std::string::npos
66 && s
.find("list") == std::string::npos
&& s
.find("vector") == std::string::npos
67 && s
.find("set") == std::string::npos
&& s
.find("map") == std::string::npos
68 && s
.find("stack") == std::string::npos
&& s
.find("queue") == std::string::npos
)
72 if (s
.find("unique_ptr") != std::string::npos
) {
73 expr
->getArg(1)->dump();
75 DiagnosticsEngine::Warning
,
76 "do not call operator== on a std container containing a unique_ptr " + s
,
83 loplugin::Plugin::Registration
< PtrVector
> X("ptrvector");
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */