Files
libreoffice/compilerplugins/clang/test/loopvartoosmall.cxx
Stephan Bergmann 2258f33a5f Make loplugin:loopvartoosmall find more suspicious cases
...where the "controlling expression" of any sort of loop contains a sub-
expression of the form

  var < val

where the type of var is smaller than that of val.  Theoretically, this could
turn up lots of false positives, but practically it didn't run into any.  Most
findings have been cleaned up over the last weeks.  There's just a handful
remaining places that are hard to clean up, so I flagged them here with
(deliberately awkward) sal::static_int_cast for later clean-up.

Change-Id: I0f735d46dda15b9b336150095df65cf247e9d6d3
Reviewed-on: https://gerrit.libreoffice.org/35682
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
2017-03-25 16:21:34 +00:00

25 lines
1.1 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <cstdint>
std::int32_t size() { return 1; }
int main() {
for (std::int16_t i = 0; i < size(); ++i) {} // expected-error {{[loplugin:loopvartoosmall]}}
for (std::int16_t i = 0; i <= size(); ++i) {} // expected-error {{[loplugin:loopvartoosmall]}}
for (std::int16_t i = 0; i != size(); ++i) {} // expected-error {{[loplugin:loopvartoosmall]}}
std::int16_t j;
for (j = 0; j < size(); ++j) {} // expected-error {{[loplugin:loopvartoosmall]}}
for (j = 0; j <= size(); ++j) {} // expected-error {{[loplugin:loopvartoosmall]}}
for (j = 0; j != size(); ++j) {} // expected-error {{[loplugin:loopvartoosmall]}}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */