diff --git a/lib/forwardanalyzer.cpp b/lib/forwardanalyzer.cpp index 7a1fd2afb..fdf324e7e 100644 --- a/lib/forwardanalyzer.cpp +++ b/lib/forwardanalyzer.cpp @@ -382,7 +382,7 @@ struct ForwardTraversal { bool checkThen = true; bool checkElse = false; if (condTok && !Token::simpleMatch(condTok, ":")) - std::tie(checkThen, checkElse) = evalCond(condTok, isDoWhile ? endBlock->link()->previous() : nullptr); + std::tie(checkThen, checkElse) = evalCond(condTok, isDoWhile ? endBlock->previous() : nullptr); if (checkElse && exit) return Progress::Continue; // do while(false) is not really a loop diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 7503b76f0..e94f3d106 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3671,6 +3671,23 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #10362 + check("int tok;\n" + "void next();\n" + "void parse_attribute() {\n" + " if (tok == '(') {\n" + " int parenthesis = 0;\n" + " do {\n" + " if (tok == '(')\n" + " parenthesis++;\n" + " else if (tok == ')')\n" + " parenthesis--;\n" + " next();\n" + " } while (parenthesis && tok != -1);\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueInfer() {