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.
// 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;
}
}