[PATCH] D53974: [clang-tidy] new check: bugprone-too-small-loop-variable

Whisperity via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 11 02:33:33 PST 2018

whisperity added a comment.

In https://reviews.llvm.org/D53974#1294385, @ztamas wrote:

> I also tested on LLVm code.
>  The output is here:
>  https://gist.github.com/tzolnai/fe4f23031d3f9fdbdbf1ee38abda00a4
> I found 362 warnings.
> Around 95% of these warnings are similar to the next example:
>   /home/zolnai/lohome/llvm/lib/Support/Chrono.cpp:64:24: warning: loop variable has narrower type 'unsigned int' than iteration's upper bound 'size_t' (aka 'unsigned long') [bugprone-too-small-loop-variable]
>     for (unsigned I = 0; I < Style.size(); ++I) {
> Where the loop variable has an `unsigned int` type while in the loop condition it is compared with a container size which has `size_t` type. The actual size method can be `std::string::length()` or `array_lengthof()` too.
> //[snip snip]//
> I can't see similar false positives what LibreOffice code produces.

I am fairly concerned the example with unsigned use for container iteration are not false positives, just examples of bad happenstance code which never breaks under real life applications due to uint32_t being good enough but is actually not type-safe.
Those examples that I kept in my quote are especially bad and should be fixed eventually...

  rCTE Clang Tools Extra


More information about the cfe-commits mailing list