Skip to content

Commit 58fb2e7

Browse files
committed
Value flow: added bailout on }
1 parent 39b47cc commit 58fb2e7

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/valueflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
100100
if (var && tok2 == var->nameToken())
101101
break;
102102
}
103+
104+
if (tok2->str() == "}") {
105+
if (settings->debugwarnings)
106+
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + " stopping on }");
107+
break;
108+
}
103109
}
104110
}
105111
}

test/testvalueflow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class TestValueFlow : public TestFixture {
8181
"}";
8282
ASSERT_EQUALS(true, testValueOfX(code, 2U, 123));
8383

84+
// bailout: if/else/etc
85+
bailout("void f(int x) {\n"
86+
" if (x != 123) { b = x; }\n"
87+
" if (x == 123) {}\n"
88+
"}");
89+
ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: variable x stopping on }\n", errout.str());
90+
8491
// bailout: assignment
8592
bailout("void f(int x) {\n"
8693
" x = y;\n"

0 commit comments

Comments
 (0)