Fix issue 9738: ValueFlow: handle std::tie better (#2657)

This commit is contained in:
Paul Fultz II 2020-05-22 15:57:20 -05:00 committed by GitHub
parent d1279856d5
commit 526abd4b52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -110,6 +110,8 @@ struct ForwardTraversal {
ForwardAnalyzer::Action action = analyzer->analyze(tok);
if (!action.isNone())
analyzer->update(tok, action);
if (action.isInconclusive() && !analyzer->lowerToInconclusive())
return Progress::Break;
if (action.isInvalid())
return Progress::Break;
return Progress::Continue;

View File

@ -93,6 +93,7 @@ private:
TEST_CASE(valueFlowForwardTernary);
TEST_CASE(valueFlowForwardLambda);
TEST_CASE(valueFlowForwardTryCatch);
TEST_CASE(valueFlowForwardInconclusiveImpossible);
TEST_CASE(valueFlowFwdAnalysis);
@ -2684,6 +2685,19 @@ private:
ASSERT_EQUALS(false, testValueOfX(code,3U,16));
}
void valueFlowForwardInconclusiveImpossible() {
const char *code;
code = "void foo() {\n"
" bool valid = f1();\n"
" if (!valid) return;\n"
" std::tie(endVal, valid) = f2();\n"
" bool x = !valid;"
" bool b = x;" // <- not always true
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 6U, 1));
}
void valueFlowRightShift() {
const char *code;
/* Set some temporary fixed values to simplify testing */