ValueFlow: set value for char literals
This commit is contained in:
parent
34dbc3c00c
commit
595f1e1a27
|
@ -598,6 +598,25 @@ static void valueFlowNumber(TokenList *tokenlist)
|
|||
ValueFlow::Value value(MathLib::toLongNumber(tok->str()));
|
||||
value.setKnown();
|
||||
setTokenValue(tok, value);
|
||||
} else if (tok->tokType() == Token::eChar) {
|
||||
char c;
|
||||
if (tok->str() == "\'\\n\'")
|
||||
c = '\n';
|
||||
else if (tok->str() == "\'\\r\'")
|
||||
c = '\r';
|
||||
else if (tok->str() == "\'\\t\'")
|
||||
c = '\t';
|
||||
else if (tok->str().size() == 3U &&
|
||||
tok->str()[0] == '\'' &&
|
||||
(tok->str()[1] & 0x80) == 0 &&
|
||||
tok->str()[2] == '\'')
|
||||
c = tok->str()[1];
|
||||
else
|
||||
continue;
|
||||
|
||||
ValueFlow::Value value(c);
|
||||
value.setKnown();
|
||||
setTokenValue(tok, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -165,8 +165,10 @@ private:
|
|||
|
||||
void valueFlowNumber() {
|
||||
ASSERT_EQUALS(123, valueOfTok("x=123;", "123").intvalue);
|
||||
ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue);
|
||||
ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue);
|
||||
ASSERT_EQUALS(0, valueOfTok("x=false;", "false").intvalue);
|
||||
ASSERT_EQUALS(1, valueOfTok("x=true;", "true").intvalue);
|
||||
ASSERT_EQUALS((int)('a'), valueOfTok("x='a';", "'a'").intvalue);
|
||||
ASSERT_EQUALS((int)('\n'), valueOfTok("x='\\n';", "'\\n'").intvalue);
|
||||
}
|
||||
|
||||
void valueFlowString() {
|
||||
|
|
Loading…
Reference in New Issue