missing return; fixed false positive for 'return {};'
This commit is contained in:
parent
4fd33ef2b5
commit
6cb8f87798
|
@ -274,6 +274,10 @@ static const Token *checkMissingReturnScope(const Token *tok)
|
||||||
if (tok->str() == "{")
|
if (tok->str() == "{")
|
||||||
return tok->next();
|
return tok->next();
|
||||||
if (tok->str() == "}") {
|
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) {
|
if (tok->scope()->type == Scope::ScopeType::eSwitch) {
|
||||||
// find break/default
|
// find break/default
|
||||||
bool hasDefault = false;
|
bool hasDefault = false;
|
||||||
|
|
|
@ -1397,6 +1397,15 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue