diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 1078a167d..7b6b22678 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -725,6 +725,12 @@ void execute(const Token* expr, *result = 0; else *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 *error = true; } diff --git a/test/teststl.cpp b/test/teststl.cpp index 9415f8f41..ac0d38de4 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -563,6 +563,32 @@ private: " return false;\n" "}\n"); 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 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 v;\n" + " if (g())\n" + " v.emplace_back(x);\n" + " const auto n = static_cast(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() {