/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * Based on LLVM/Clang. * * This file is distributed under the University of Illinois Open Source * License. See LICENSE.TXT for details. * */ #include "bodynotinblock.hxx" namespace loplugin { /* This is a compile check. Check for two statements that are both indented to look like a body of if/while/for but are not inside a compound statement and thus the second one is unrelated. For example: if( a != 0 ) b = 2; c = 3; Here either both statements should be inside {} or the second statement in indented wrong. */ BodyNotInBlock::BodyNotInBlock( const InstantiationData& data ) : Plugin( data ) { } void BodyNotInBlock::run() { TraverseDecl( compiler.getASTContext().getTranslationUnitDecl()); } bool BodyNotInBlock::VisitIfStmt( const IfStmt* stmt ) { if( ignoreLocation( stmt )) return true; checkBody( stmt->getThen(), stmt->getIfLoc(), 0, stmt->getElse() != NULL ); checkBody( stmt->getElse(), stmt->getElseLoc(), 0 ); return true; } bool BodyNotInBlock::VisitWhileStmt( const WhileStmt* stmt ) { if( ignoreLocation( stmt )) return true; checkBody( stmt->getBody(), stmt->getWhileLoc(), 1 ); return true; } bool BodyNotInBlock::VisitForStmt( const ForStmt* stmt ) { if( ignoreLocation( stmt )) return true; checkBody( stmt->getBody(), stmt->getForLoc(), 2 ); return true; } bool BodyNotInBlock::VisitCXXForRangeStmt( const CXXForRangeStmt* stmt ) { if( ignoreLocation( stmt )) return true; checkBody( stmt->getBody(), stmt->getForLoc(), 2 ); return true; } void BodyNotInBlock::checkBody( const Stmt* body, SourceLocation stmtLocation, int stmtType, bool dontGoUp ) { if( body == NULL ) return; // TODO: If the if/else/while/for comes from a macro expansion, ignore it completely for // now. The code below could assume everything is in the same place (and thus also column) // and give a false warning. Moreover some macros are rather lousily written and would // result in poor formatting. To be evaluated later, maybe this could be handled // including macro expansion. if( stmtLocation.isMacroID()) return; if( dyn_cast< CompoundStmt >( body )) return; // if body is a compound statement, then it is in {} const Stmt* previousParent = parentStmt( body ); // Here the statement itself. // Find the next statement (in source position) after 'body'. for(;;) { const Stmt* parent = parentStmt( previousParent ); if( parent == NULL ) break; for( ConstStmtIterator it = parent->child_begin(); it != parent->child_end(); ) { if( *it == previousParent ) // found grand(grand...)parent { // get next statement after our (grand...)parent ++it; while( it != parent->child_end() && *it == NULL ) ++it; // skip empty ones (missing 'else' bodies for example) if( it != parent->child_end()) { bool invalid1, invalid2; unsigned bodyColumn = compiler.getSourceManager() .getPresumedColumnNumber( body->getLocStart(), &invalid1 ); unsigned nextStatementColumn = compiler.getSourceManager() .getPresumedColumnNumber( (*it)->getLocStart(), &invalid2 ); if( invalid1 || invalid2 ) return; if( bodyColumn == nextStatementColumn ) { report( DiagnosticsEngine::Warning, "statement aligned as second statement in %select{if|while|for}0 body but not in a statement block", (*it)->getLocStart()) << stmtType; report( DiagnosticsEngine::Note, "%select{if|while|for}0 body statement is here", body->getLocStart()) << stmtType; } return; } // else we need to go higher to find the next statement } else ++it; } // If going up would mean leaving a {} block, stop, because the } should // make it visible the two statements are not in the same body. if( dyn_cast< CompoundStmt >( parent )) return; // If the body to be checked is a body of an if statement that has also // an else part, don't go up, the else is after the body and should make // it clear the body does not continue there. if( dontGoUp ) return; previousParent = parent; } } static Plugin::Registration< BodyNotInBlock > X( "bodynotinblock" ); } // namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ nt in ConstToBool::VisitImplicitCastExpr), we get more warnings about uses of 'TRUE' than of 'FALSE'. For example, in libreofficekit/source/gtk/lokdocview.cxx there is a warning about the 'TRUE' in g_main_context_iteration(nullptr, TRUE); but not about the 'FALSE' in g_main_context_iteration(nullptr, FALSE); (where the parameter of 'g_main_context_iteration' is of type 'gboolean'). Lets live with that asymmetry for now... (Besides the issues addressed directly in this commit, it also found the two bogus asserts at 7e09d08807b5ba2fd8b9831557752a415bdad562 "Fix useless assert(true) (which would never fire)" and 122a0be8ae480473bd1d7f35e197a2529f4621e3 "Fix useless assert(true) (which would never fire)", plus 5f0d6df7f57ae281fe161e61c7f25d67453fddd2 "Use two-argument form of static_assert".) Change-Id: Id77322de9f94b85a7b65608a03e0e9865d14467b Reviewed-on: https://gerrit.libreoffice.org/82667 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
...to: "Find implicit conversions from non-'bool' constants (e.g., 'sal_False')
to 'bool'".

Due to how FALSE is defined as just

  #define FALSE (0)

(i.e., a literal of type 'int') but TRUE is defined as

  #define TRUE (!FALSE)

(i.e., an implicit conversion from 'int' to 'bool') in GLib (see the comment in
ConstToBool::VisitImplicitCastExpr), we get more warnings about uses of 'TRUE'
than of 'FALSE'.  For example, in libreofficekit/source/gtk/lokdocview.cxx there
is a warning about the 'TRUE' in

  g_main_context_iteration(nullptr, TRUE);

but not about the 'FALSE' in

  g_main_context_iteration(nullptr, FALSE);

(where the parameter of 'g_main_context_iteration' is of type 'gboolean').  Lets
live with that asymmetry for now...

(Besides the issues addressed directly in this commit, it also found the two
bogus asserts at 7e09d08807b5ba2fd8b9831557752a415bdad562 "Fix useless
assert(true) (which would never fire)" and
122a0be8ae480473bd1d7f35e197a2529f4621e3 "Fix useless assert(true) (which would
never fire)", plus 5f0d6df7f57ae281fe161e61c7f25d67453fddd2 "Use two-argument
form of static_assert".)

Change-Id: Id77322de9f94b85a7b65608a03e0e9865d14467b
Reviewed-on: https://gerrit.libreoffice.org/82667
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Extend loplugin:salbool to loplugin:fakebool 2019-11-13T14:06:42+00:00 Stephan Bergmann sbergman@redhat.com 2019-11-12T20:53:31+00:00 913d34ec6b8fdb2796f76ce90fee51ade2051189 ...checking for unnecessary uses of more "fake bool" types. In the past, some of the checks involving the types of variables or data members, or the return types of functions, issued warnings that required surrounding code to be changed too (e.g., when changing the signature of a function whose address was taken). These checks have been tightened now to not warn in such cases (which avoids warnings that require changes to additional code, or changes that might even be impossible to make, at the cost of being less aggressive about removing all unnecessary uses of those "fake bool" types). Change-Id: I70eb75039817cda34ed611387ee27dc5f36a3e2e Reviewed-on: https://gerrit.libreoffice.org/82554 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
...checking for unnecessary uses of more "fake bool" types.

In the past, some of the checks involving the types of variables or data
members, or the return types of functions, issued warnings that required
surrounding code to be changed too (e.g., when changing the signature of a
function whose address was taken).  These checks have been tightened now to not
warn in such cases (which avoids warnings that require changes to additional
code, or changes that might even be impossible to make, at the cost of being
less aggressive about removing all unnecessary uses of those "fake bool" types).

Change-Id: I70eb75039817cda34ed611387ee27dc5f36a3e2e
Reviewed-on: https://gerrit.libreoffice.org/82554
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
tdf#42949 Fix IWYU warnings in vcl/unx/gtk3 and gtk3_kde5/ 2019-10-25T08:15:07+00:00 Gabor Kelemen kelemen.gabor2@nisz.hu 2019-10-20T11:25:53+00:00 07359ea21cf27e29d3e642d6ff1851155888a875 Also recheck vcl/source after recent reworks and f-u-i updates. Some new blacklist entries were needed for keeping existing fw declarations in headers. Add blacklist entries for removals causing no-pch build failures that were reverted in: a3b03ba1316b1ec0a9b0a3b45b96dc0a49aa9f1f 75d924db95559cff5f699bad8fe34bb0aeac0ff6 b57052ec2bbe548ca495a32b4bfce1d1c71caf33 Found with bin/find-unneeded-includes Only removal proposals are dealt with here. Change-Id: I71227806288b68ef2a2cd56244899fd56bd0db8d Reviewed-on: https://gerrit.libreoffice.org/81163 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Also recheck vcl/source after recent reworks and f-u-i updates.
Some new blacklist entries were needed for keeping existing
fw declarations in headers.

Add blacklist entries for removals causing no-pch build failures
that were reverted in:
a3b03ba1316b1ec0a9b0a3b45b96dc0a49aa9f1f
75d924db95559cff5f699bad8fe34bb0aeac0ff6
b57052ec2bbe548ca495a32b4bfce1d1c71caf33

Found with bin/find-unneeded-includes
Only removal proposals are dealt with here.

Change-Id: I71227806288b68ef2a2cd56244899fd56bd0db8d
Reviewed-on: https://gerrit.libreoffice.org/81163
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
drop gtk2 support 2019-09-30T14:53:32+00:00 Caolán McNamara caolanm@redhat.com 2019-08-13T09:37:50+00:00 1ae450504cf57457f9702684b1517fda1dd3c481 Change-Id: Ie838cabfecfef7e3225c1555536d5c9cf3b43f15 Reviewed-on: https://gerrit.libreoffice.org/77405 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Change-Id: Ie838cabfecfef7e3225c1555536d5c9cf3b43f15
Reviewed-on: https://gerrit.libreoffice.org/77405
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>