Remove false positive in AvoidNonConstGlobalVariables.

Addresses post-commit review feedback from https://reviews.llvm.org/D70265
This commit is contained in:
Kim Viggedal 2020-04-15 14:47:11 -04:00 committed by Aaron Ballman
parent 25db295756
commit b2d8c89ea4
2 changed files with 7 additions and 2 deletions

View File

@ -17,11 +17,15 @@ namespace clang {
namespace tidy {
namespace cppcoreguidelines {
namespace {
AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
} // namespace
void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
auto GlobalVariable = varDecl(
hasGlobalStorage(),
unless(anyOf(
isConstexpr(), hasType(isConstQualified()),
isLocalVarDecl(), isConstexpr(), hasType(isConstQualified()),
hasType(referenceType())))); // References can't be changed, only the
// data they reference can be changed.

View File

@ -231,7 +231,8 @@ constexpr T templateVariable = T(0L);
// 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;
}
}