diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 4e17c5787..d10e2b6e1 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -316,6 +316,9 @@ static const Token *checkMissingReturnScope(const Token *tok, const Library &lib if (!hasDefault) return tok->link(); } else if (tok->scope()->type == Scope::ScopeType::eIf) { + const Token *condition = tok->scope()->classDef->next()->astOperand2(); + if (condition && condition->hasKnownIntValue() && condition->getKnownIntValue() == 1) + return checkMissingReturnScope(tok, library); return tok; } else if (tok->scope()->type == Scope::ScopeType::eElse) { const Token *errorToken = checkMissingReturnScope(tok, library); diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 7cd843bd5..b3495c0cf 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1436,6 +1436,18 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str()); + check("int f() {\n" + " if (!0) {\n" + " return 1;\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + + check("int f() {\n" + " if (!0) {}\n" + "}"); + ASSERT_EQUALS("[test.cpp:2]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str()); + // loop check("int f(int x) {\n" " while (1) {\n"