vingeldal updated this revision to Diff 257060.
vingeldal added a comment.
Ran automatic formatting on the patch
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77461/new/
https://reviews.llvm.org/D77461
Files:
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
Index:
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
===================================================================
---
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
+++
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
@@ -231,7 +231,8 @@
// CHECKING AGAINST FALSE POSITIVES INSIDE FUNCTION SCOPE /////////////////////
int main() {
for (int i = 0; i < 3; ++i) {
+ static int staticNonConstLoopVariable = 42;
int nonConstLoopVariable = 42;
- nonConstInt = nonConstLoopVariable + i;
+ nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
}
}
Index:
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
===================================================================
---
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
+++
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
@@ -45,11 +45,15 @@
if (const auto *Variable =
Result.Nodes.getNodeAs<VarDecl>("non-const_variable")) {
- diag(Variable->getLocation(), "variable %0 is non-const and globally "
- "accessible, consider making it const")
- << Variable; // FIXME: Add fix-it hint to Variable
- // Don't return early, a non-const variable may also be a pointer or
- // reference to non-const data.
+ // To avoid warning about local variables with global storage, like static
+ // variables in a function.
+ if (!Variable->isLocalVarDecl()) {
+ diag(Variable->getLocation(), "variable %0 is non-const and globally "
+ "accessible, consider making it const")
+ << Variable; // FIXME: Add fix-it hint to Variable
+ // Don't return early, a non-const variable may also be a pointer or
+ // reference to non-const data.
+ }
}
if (const auto *VD =
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
@@ -231,7 +231,8 @@
// CHECKING AGAINST FALSE POSITIVES INSIDE FUNCTION SCOPE /////////////////////
int main() {
for (int i = 0; i < 3; ++i) {
+ static int staticNonConstLoopVariable = 42;
int nonConstLoopVariable = 42;
- nonConstInt = nonConstLoopVariable + i;
+ nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
}
}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
@@ -45,11 +45,15 @@
if (const auto *Variable =
Result.Nodes.getNodeAs<VarDecl>("non-const_variable")) {
- diag(Variable->getLocation(), "variable %0 is non-const and globally "
- "accessible, consider making it const")
- << Variable; // FIXME: Add fix-it hint to Variable
- // Don't return early, a non-const variable may also be a pointer or
- // reference to non-const data.
+ // To avoid warning about local variables with global storage, like static
+ // variables in a function.
+ if (!Variable->isLocalVarDecl()) {
+ diag(Variable->getLocation(), "variable %0 is non-const and globally "
+ "accessible, consider making it const")
+ << Variable; // FIXME: Add fix-it hint to Variable
+ // Don't return early, a non-const variable may also be a pointer or
+ // reference to non-const data.
+ }
}
if (const auto *VD =
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits