missing return; fixed false positive for 'return {};'

This commit is contained in:
Daniel Marjamäki 2021-07-04 19:57:43 +02:00
parent 4fd33ef2b5
commit 6cb8f87798
2 changed files with 13 additions and 0 deletions

View File

@ -274,6 +274,10 @@ static const Token *checkMissingReturnScope(const Token *tok)
if (tok->str() == "{")
return tok->next();
if (tok->str() == "}") {
for (const Token *prev = tok->link()->previous(); prev && prev->scope() == tok->scope() && !Token::Match(prev, "[;{}]"); prev = prev->previous()) {
if (prev->isKeyword() && Token::Match(prev, "return|throw"))
return nullptr;
}
if (tok->scope()->type == Scope::ScopeType::eSwitch) {
// find break/default
bool hasDefault = false;

View File

@ -1397,6 +1397,15 @@ private:
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
// return {..}
check("std::pair<int, int> typeDecl(int tok) {\n"
" if (!tok)\n"
" return {};\n"
" else\n"
" return {1, 2};\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};