Skip to content

Refactor valueFlowTerminatingCondition to handle inner conditions and complex conditions#3060

Merged
danmar merged 8 commits into
cppcheck-opensource:mainfrom
pfultz2:valueflow-condition-expression
Jan 21, 2021
Merged

Refactor valueFlowTerminatingCondition to handle inner conditions and complex conditions#3060
danmar merged 8 commits into
cppcheck-opensource:mainfrom
pfultz2:valueflow-condition-expression

Conversation

@pfultz2

@pfultz2 pfultz2 commented Jan 17, 2021

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread lib/valueflow.cpp Outdated
}

static void valueFlowTerminatingCondition(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings)
ValueFlow::Value MakeConditionValue(long long val, const Token* condTok, bool assume)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest leading "m"

Comment thread test/testcondition.cpp Outdated
"test.cpp:2:note:'y' is assigned value 'x' here.\n"
"test.cpp:3:note:first condition\n"
"test.cpp:4:note:else if condition is opposite to first condition\n", errout.str());
ASSERT_EQUALS("test.cpp:4:style:Condition '!y' is always true\n"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old warning was much easier to read. I do not expect that a user will always understand why cppcheck thinks that conditions are always true/false. The real world cases will not be obvious.

Comment thread test/testcondition.cpp
" else { if (a == 2) { b = 3; } } }\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Condition 'a==2' is always false\n", errout.str());
ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout.str());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 💯

@danmar danmar merged commit f1cc3ad into cppcheck-opensource:main Jan 21, 2021
@pfultz2 pfultz2 deleted the valueflow-condition-expression branch January 21, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants