diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index d10e2b6e1..831103759 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -257,6 +257,8 @@ void CheckFunctions::checkMissingReturn() const Function *function = scope->function; if (!function || !function->hasBody()) continue; + if (function->name() == "main" && !(mSettings->standards.c < Standards::C99 && mTokenizer->isC())) + continue; if (function->type != Function::Type::eFunction && function->type != Function::Type::eOperatorEqual) continue; if (Token::Match(function->retDef, "%name% (") && function->retDef->isUpperCaseName()) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 3230829f6..61d51e8fb 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -1373,6 +1373,21 @@ private: check("int f() {}"); ASSERT_EQUALS("[test.cpp:1]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str()); + { + const char code[] = "int main(void) {}"; + Settings s; + + s.standards.c = Standards::C89; + check(code, "test.c", &s); // c code (c89) + ASSERT_EQUALS("[test.c:1]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str()); + + s.standards.c = Standards::C99; check(code, "test.c", &s); // c code (c99) + ASSERT_EQUALS("", errout.str()); + + check(code, "test.cpp", &s); // c++ code + ASSERT_EQUALS("", errout.str()); + } + check("F(A,B) { x=1; }"); ASSERT_EQUALS("", errout.str());