Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / compilerplugins / clang / charrightshift.cxx
blobfe21cd8c84683bb2569646f679091425e7372ae5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 "check.hxx"
11 #include "plugin.hxx"
13 namespace {
15 class CharRightShift:
16 public RecursiveASTVisitor<CharRightShift>, public loplugin::Plugin
18 public:
19 explicit CharRightShift(loplugin::InstantiationData const & data):
20 Plugin(data) {}
22 void run() override
23 { TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()); }
25 bool VisitBinShr(BinaryOperator const * expr) {
26 if (ignoreLocation(expr)) {
27 return true;
29 auto t = expr->getLHS()->IgnoreParenImpCasts()->getType();
30 if (!loplugin::TypeCheck(t).Char()) {
31 return true;
33 if (!expr->getRHS()->getType()->isBuiltinType()) {
34 //TODO: in which case the expression should be an
35 // CXXOperatorCallExpr instead of a BinaryOperator? but at least
36 // recent Clang trunk reports
38 // '(' >> orExpression
40 // (connectivity/source/commontools/RowFunctionParser.cxx, the RHS
41 // being of type boost::spirit::rule<ScannerT>) here
42 return true;
44 report(
45 DiagnosticsEngine::Warning,
46 ("right shift of %0 is implementation-defined when 'char' is signed"
47 " and value is negative"),
48 expr->getLHS()->getExprLoc())
49 << t << expr->getSourceRange();
50 return true;
54 loplugin::Plugin::Registration<CharRightShift> X("charrightshift");
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */