Skip to content

Commit da58a61

Browse files
Fix #14193 FP knownConditionTrueFalse for loop references to container elements (#7884)
Co-authored-by: chrchr-github <[email protected]>
1 parent 7828eb5 commit da58a61

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/astutils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,8 @@ static const Token * followVariableExpression(const Settings& settings, const To
12031203
return tok;
12041204
if (hasUnknownVars(varTok))
12051205
return tok;
1206+
if (astIsRangeBasedForDecl(var->nameToken()))
1207+
return tok;
12061208
if (var->isVolatile())
12071209
return tok;
12081210
if (!var->isLocal() && !var->isConst())

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8040,6 +8040,15 @@ class TestOther : public TestFixture {
80408040
" }\n"
80418041
"}\n");
80428042
ASSERT_EQUALS("", errout_str());
8043+
8044+
check("void f(const std::vector<int>& v) {\n" // #14193
8045+
" for (const int& r1 : v) {\n"
8046+
" for (const int& r2 : v) {\n"
8047+
" if (&r1 == &r2) {}\n"
8048+
" }\n"
8049+
" }\n"
8050+
"}\n");
8051+
ASSERT_EQUALS("", errout_str());
80438052
}
80448053

80458054
void duplicateExpressionTernary() { // #6391

0 commit comments

Comments
 (0)