value flow: assume that value of global const variable is not changed
This commit is contained in:
parent
a26c5736da
commit
d085705e8f
|
@ -50,7 +50,7 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
|||
unsigned int varid;
|
||||
MathLib::bigint num;
|
||||
const Variable *var;
|
||||
if (tok->isComparisonOp() && tok->astOperand1() && tok->astOperand2()) {
|
||||
if (tok->isComparisonOp() && tok->astOperand2()) {
|
||||
if (tok->astOperand1()->isName() && tok->astOperand2()->isNumber()) {
|
||||
varid = tok->astOperand1()->varId();
|
||||
var = tok->astOperand1()->variable();
|
||||
|
@ -78,8 +78,8 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog
|
|||
if (varid == 0U)
|
||||
continue;
|
||||
|
||||
// bailout: global variables
|
||||
if (var && var->isGlobal()) {
|
||||
// bailout: global non-const variables
|
||||
if (var && var->isGlobal() && !var->isConst()) {
|
||||
if (settings->debugwarnings)
|
||||
bailout(tokenlist, errorLogger, tok, "global variable " + var->nameToken()->str());
|
||||
continue;
|
||||
|
|
|
@ -97,6 +97,13 @@ private:
|
|||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 2U, 0));
|
||||
|
||||
code = "extern const int x;\n"
|
||||
"void f() {\n"
|
||||
" int a = x;\n"
|
||||
" if (x == 123) {}\n"
|
||||
"}";
|
||||
ASSERT_EQUALS(true, testValueOfX(code, 3U, 123));
|
||||
|
||||
// bailout: ?:
|
||||
bailout("void f(int x) {\n"
|
||||
" y = ((x<0) ? x : ((x==2)?3:4));\n"
|
||||
|
|
Loading…
Reference in New Issue