forked from OSchip/llvm-project
Remove false positive in AvoidNonConstGlobalVariables.
Addresses post-commit review feedback from https://reviews.llvm.org/D70265
This commit is contained in:
parent
25db295756
commit
b2d8c89ea4
|
@ -17,11 +17,15 @@ namespace clang {
|
||||||
namespace tidy {
|
namespace tidy {
|
||||||
namespace cppcoreguidelines {
|
namespace cppcoreguidelines {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
|
||||||
|
} // namespace
|
||||||
|
|
||||||
void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
|
void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
|
||||||
auto GlobalVariable = varDecl(
|
auto GlobalVariable = varDecl(
|
||||||
hasGlobalStorage(),
|
hasGlobalStorage(),
|
||||||
unless(anyOf(
|
unless(anyOf(
|
||||||
isConstexpr(), hasType(isConstQualified()),
|
isLocalVarDecl(), isConstexpr(), hasType(isConstQualified()),
|
||||||
hasType(referenceType())))); // References can't be changed, only the
|
hasType(referenceType())))); // References can't be changed, only the
|
||||||
// data they reference can be changed.
|
// data they reference can be changed.
|
||||||
|
|
||||||
|
|
|
@ -231,7 +231,8 @@ constexpr T templateVariable = T(0L);
|
||||||
// CHECKING AGAINST FALSE POSITIVES INSIDE FUNCTION SCOPE /////////////////////
|
// CHECKING AGAINST FALSE POSITIVES INSIDE FUNCTION SCOPE /////////////////////
|
||||||
int main() {
|
int main() {
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
|
static int staticNonConstLoopVariable = 42;
|
||||||
int nonConstLoopVariable = 42;
|
int nonConstLoopVariable = 42;
|
||||||
nonConstInt = nonConstLoopVariable + i;
|
nonConstInt = nonConstLoopVariable + i + staticNonConstLoopVariable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue