[PATCH] D77461: [WIP][clang-tidy] Remove false positive in AvoidNonConstGlobalVariables

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 14 04:46:00 PDT 2020


aaron.ballman added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp:50
+    // variables in a function.
+    if (!Variable->isLocalVarDecl()) {
+      diag(Variable->getLocation(), "variable %0 is non-const and globally "
----------------
I think this should be handled in the matcher rather than here. I'd add a local matcher for `isLocalVarDecl()` and add it to the `unless()` matcher. WDYT?


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp:234-236
+    static int staticNonConstLoopVariable = 42;
     int nonConstLoopVariable = 42;
+    nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
----------------
I would like this example moved out of the section suggesting this is a false positive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77461





More information about the cfe-commits mailing list