cURL: follow redirects
[LibreOffice.git] / compilerplugins / clang / commaoperator.cxx
blob39a2b9cb872076109f5b4856c1d457c721718935
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 */
10 #include <cassert>
11 #include <string>
12 #include <iostream>
13 #include <fstream>
14 #include <set>
15 #include "plugin.hxx"
17 /**
18 the comma operator is best used sparingly
21 namespace {
23 class CommaOperator:
24 public RecursiveASTVisitor<CommaOperator>, public loplugin::Plugin
26 public:
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)) {
40 return true;
42 if (binaryOp->getOpcode() != BO_Comma) {
43 return true;
45 const Stmt* parent = parentStmt(binaryOp);
46 if (parent != nullptr) {
47 if (isa<ParenExpr>(parent)) {
48 return true;
50 if (isa<BinaryOperator>(parent)) {
51 return true;
53 if (isa<ForStmt>(parent)) {
54 return true;
56 if (isa<ExprWithCleanups>(parent)) {
57 const Stmt* parent2 = parentStmt(parent);
58 if (isa<ForStmt>(parent2)) {
59 return true;
63 // parent->dump();
64 report(
65 DiagnosticsEngine::Warning, "comma operator hides code",
66 binaryOp->getSourceRange().getBegin())
67 << binaryOp->getSourceRange();
68 return true;
72 loplugin::Plugin::Registration< CommaOperator > X("commaoperator", true);
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */