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/.
18 the comma operator is best used sparingly
24 public RecursiveASTVisitor
<CommaOperator
>, public loplugin::Plugin
27 explicit CommaOperator(InstantiationData
const & data
): Plugin(data
) {}
29 virtual void run() override
31 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
34 bool VisitBinaryOperator(const BinaryOperator
* );
37 bool CommaOperator::VisitBinaryOperator(const BinaryOperator
* binaryOp
)
39 if (ignoreLocation(binaryOp
)) {
42 if (binaryOp
->getOpcode() != BO_Comma
) {
45 const Stmt
* parent
= parentStmt(binaryOp
);
46 if (parent
!= nullptr) {
47 if (isa
<ParenExpr
>(parent
)) {
50 if (isa
<BinaryOperator
>(parent
)) {
53 if (isa
<ForStmt
>(parent
)) {
56 if (isa
<ExprWithCleanups
>(parent
)) {
57 const Stmt
* parent2
= parentStmt(parent
);
58 if (isa
<ForStmt
>(parent2
)) {
65 DiagnosticsEngine::Warning
, "comma operator hides code",
66 binaryOp
->getSourceRange().getBegin())
67 << binaryOp
->getSourceRange();
72 loplugin::Plugin::Registration
< CommaOperator
> X("commaoperator", true);
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */