Evaluate casts in programmemory (#3359)
This commit is contained in:
parent
14802b932e
commit
0d3afbb954
|
@ -725,6 +725,12 @@ void execute(const Token* expr,
|
||||||
*result = 0;
|
*result = 0;
|
||||||
else
|
else
|
||||||
*error = true;
|
*error = true;
|
||||||
|
}
|
||||||
|
else if (expr->str() == "(" && expr->isCast()) {
|
||||||
|
if (Token::simpleMatch(expr->previous(), ">") && expr->previous()->link())
|
||||||
|
execute(expr->astOperand2(), programMemory, result, error);
|
||||||
|
else
|
||||||
|
execute(expr->astOperand1(), programMemory, result, error);
|
||||||
} else
|
} else
|
||||||
*error = true;
|
*error = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -563,6 +563,32 @@ private:
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("test.cpp:8:style:Consider using std::any_of algorithm instead of a raw loop.\n", errout.str());
|
ASSERT_EQUALS("test.cpp:8:style:Consider using std::any_of algorithm instead of a raw loop.\n", errout.str());
|
||||||
|
|
||||||
|
checkNormal("bool g();\n"
|
||||||
|
"int f(int x) {\n"
|
||||||
|
" std::vector<int> v;\n"
|
||||||
|
" if (g())\n"
|
||||||
|
" v.emplace_back(x);\n"
|
||||||
|
" const auto n = (int)v.size();\n"
|
||||||
|
" for (int i = 0; i < n; ++i)\n"
|
||||||
|
" if (v[i] > 0)\n"
|
||||||
|
" return i;\n"
|
||||||
|
" return 0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkNormal("bool g();\n"
|
||||||
|
"int f(int x) {\n"
|
||||||
|
" std::vector<int> v;\n"
|
||||||
|
" if (g())\n"
|
||||||
|
" v.emplace_back(x);\n"
|
||||||
|
" const auto n = static_cast<int>(v.size());\n"
|
||||||
|
" for (int i = 0; i < n; ++i)\n"
|
||||||
|
" if (v[i] > 0)\n"
|
||||||
|
" return i;\n"
|
||||||
|
" return 0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void outOfBoundsIndexExpression() {
|
void outOfBoundsIndexExpression() {
|
||||||
|
|
Loading…
Reference in New Issue