Fix issue 9099 and 9102: Incorrect valueflow for global variables (#1832)

This commit is contained in:
Paul Fultz II 2019-05-14 01:58:27 -05:00 committed by Daniel Marjamäki
parent 195da2b3d2
commit 4e94c64da8
2 changed files with 12 additions and 4 deletions

View File

@ -1463,9 +1463,6 @@ static void valueFlowOppositeCondition(SymbolDatabase *symboldatabase, const Set
static void valueFlowGlobalConstVar(TokenList* tokenList, const Settings *settings)
{
// TODO: danmar: This is commented out until #9099 is fixed
return;
// Get variable values...
std::map<const Variable*, ValueFlow::Value> vars;
for (const Token* tok = tokenList->front(); tok; tok = tok->next()) {
@ -1474,6 +1471,8 @@ static void valueFlowGlobalConstVar(TokenList* tokenList, const Settings *settin
// Initialization...
if (tok == tok->variable()->nameToken() &&
!tok->variable()->isStatic() &&
!tok->variable()->isVolatile() &&
!tok->variable()->isArgument() &&
tok->variable()->isConst() &&
tok->valueType() &&
tok->valueType()->isIntegral() &&

View File

@ -3194,7 +3194,16 @@ private:
"void f() {\n"
" a = x;\n"
"}";
TODO_ASSERT_EQUALS(true, false, testValueOfX(code, 3U, 321));
ASSERT_EQUALS(true, testValueOfX(code, 3U, 321));
code = "void f(const int x = 1) {\n"
" int a = x;\n"
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 2U, 1));
code = "volatile const int x = 42;\n"
"void f(){ int a = x; }\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 2U, 42));
}
void valueFlowGlobalStaticVar() {