1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #ifndef LO_CLANG_SHARED_PLUGINS
18 public loplugin::FilteringPlugin
<CharRightShift
>
21 explicit CharRightShift(loplugin::InstantiationData
const & data
):
22 FilteringPlugin(data
) {}
25 { TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl()); }
27 bool VisitBinaryOperator(BinaryOperator
const * expr
) {
28 if (expr
->getOpcode() != BO_Shr
) {
31 if (ignoreLocation(expr
)) {
34 auto t
= expr
->getLHS()->IgnoreParenImpCasts()->getType();
35 if (!loplugin::TypeCheck(t
).Char()) {
38 if (!expr
->getRHS()->getType()->isBuiltinType()) {
39 //TODO: in which case the expression should be an
40 // CXXOperatorCallExpr instead of a BinaryOperator? but at least
41 // recent Clang trunk reports
43 // '(' >> orExpression
45 // (connectivity/source/commontools/RowFunctionParser.cxx, the RHS
46 // being of type boost::spirit::rule<ScannerT>) here
50 DiagnosticsEngine::Warning
,
51 ("right shift of %0 is implementation-defined when 'char' is signed"
52 " and value is negative"),
53 expr
->getLHS()->getExprLoc())
54 << t
<< expr
->getSourceRange();
59 loplugin::Plugin::Registration
<CharRightShift
> charrightshift("charrightshift");
63 #endif // LO_CLANG_SHARED_PLUGINS
65 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */