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

Tamás Zolnai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 2 14:37:50 PDT 2018


ztamas marked 3 inline comments as done.
ztamas added inline comments.


================
Comment at: test/clang-tidy/bugprone-too-small-loop-variable.cpp:6
+void voidBadForLoop() {
+  for (int i = 0; i < size(); ++i) {
+    // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: loop variable has a narrower type ('int') than the type ('long') of termination condition [bugprone-too-small-loop-variable]
----------------
JonasToth wrote:
> ztamas wrote:
> > JonasToth wrote:
> > > please add tests where the rhs is a literal.
> > Do you mean tests like voidForLoopWithLiteralCond()?
> > Is it worth to add more tests like that?
> I didn't see it. In principle yes, but i would like to see a test with a bigger number then iterateable (maybe there is a frontend warning for that?). If there is no warning, this should definitely be implemented here (possible follow up) or even become a frontend warning.
I added a test case. This kind of test cases are caught by -Wtautological-constant-out-of-range-compare, so we are good I think.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53974





More information about the cfe-commits mailing list