[PATCH] D53974: [clang-tidy] new checker: bugprone-too-small-loop-variable
Tamás Zolnai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 1 08:01:17 PDT 2018
ztamas added a comment.
In https://reviews.llvm.org/D53974#1283833, @sberg wrote:
> > I run the new checker on LibreOffice project. I found ~25 false positives, which seems small enough to me. This false positives can be supressed easily.
>
> Do you have a link to such a false positive and how it got suppressed in the LibreOffice code base? (If those are included in the referenced https://cgit.freedesktop.org/libreoffice/core/commit/?id=26ccd00bc96c585b7065af0dcce246b5bfaae5e1, I failed to spot them.)
I did not supress anything yet, since this checker is still work in progress. The final version might avoid those false postives.
One example in basic/source/runtime/dllmgr-x86.cxx
This line:
for (sal_uInt16 i = 1; i < (arguments == 0 ? 0 : arguments->Count()); ++i)
arguments->Count() returns a sal_uInt16 too, which is unsigned short, however "0" is an int literal so the "<>?<>:<>" expression will have an int type.
To supress that you can cast the literal:
for (sal_uInt16 i = 1; i < (arguments == 0 ? (sal_uInt16)0 : arguments->Count()); ++i)
Or cast the whole expression:
for (sal_uInt16 i = 1; i < (sal_uInt16)(arguments == 0 ? 0 : arguments->Count()); ++i)
Or use int for the loop variable:
for (int i = 1; i < (arguments == 0 ? 0 : arguments->Count()); ++i)
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D53974
More information about the cfe-commits
mailing list