[PATCH] D100092: [clang-tidy] cppcoreguidelines-declare-loop-variable-in-the-initializer: a new check

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 9 03:50:19 PDT 2021


njames93 added a comment.

I'd argue this check isn't following the enforcement specified in the relevant guideline:

  Enforcement:
  Warn when a variable modified inside the for-statement is declared outside the loop and not being used outside the loop.

All this is checking is that there is a declStmt in the for stmt, it doesn't even have to be a relevant declaration, this code would be considered ok by the implementation in here.

  int I = 0;
  for (int Unused = 0; I < 10; ++I) {}

Ideally you want to check for variables modified in the condition or iteration expression that aren't declared in the init statement.
To be fully compliant with the wording you would also need to ensure the variable isn't referenced outside the loop.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100092/new/

https://reviews.llvm.org/D100092



More information about the cfe-commits mailing list