Skip to content

Commit 185c0c1

Browse files
Update checkclass.cpp
1 parent e1cfdb9 commit 185c0c1

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/checkclass.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,8 +2545,10 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
25452545
}
25462546
}
25472547
} else if (lhs->str() == ":" && lhs->astParent() && lhs->astParent()->str() == "(") { // range-based for-loop (C++11)
2548-
// TODO: We could additionally check what is done with the elements to avoid false negatives. Here we just rely on "const" keyword being used.
2549-
if (lhs->astParent()->strAt(1) != "const")
2548+
const Variable* loopVar = lhs->astOperand1()->variable();
2549+
if (!loopVar || !loopVar->valueType())
2550+
return false;
2551+
if (!loopVar->valueType()->isConst(loopVar->valueType()->pointer))
25502552
return false;
25512553
} else {
25522554
if (lhs->isAssignmentOp()) {

0 commit comments

Comments
 (0)