Fixed #4943 and simplified CheckOther::checkCommaSeparatedReturn()

This commit is contained in:
PKEuS 2013-08-06 11:27:09 -07:00
parent 1538b46970
commit dd82817752
2 changed files with 18 additions and 24 deletions

View File

@ -1882,28 +1882,11 @@ void CheckOther::checkCommaSeparatedReturn()
return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok ,"return")) {
if (tok->str() == "return") {
while (tok && tok->str() != ";") {
if (tok->str() == "(")
if (Token::Match(tok, "[([{<]") && tok->link())
tok = tok->link();
// Skip template parameters
if (tok->str() == "<" && TemplateSimplifier::templateParameters(tok) > 0U) {
unsigned int level = 1U;
while (level > 0U && NULL != (tok = tok->next())) {
if (tok->str() == "<")
level++;
else if (tok->str() == ">")
level--;
else if (tok->str() == ">>")
level = level - ((level > 1U) ? 2 : 1);
else if (tok->str() == ";")
break;
}
}
if (!tok->isExpandedMacro() && tok->str() == "," && tok->linenr() != tok->next()->linenr())
commaSeparatedReturnError(tok);

View File

@ -6345,7 +6345,7 @@ private:
check("int fun(int a) {\n"
" if (a < 0)\n"
" return a<int,\nint>::b;\n"
" return c<int,\nint>::b;\n"
"}", NULL, false, false, false, false);
ASSERT_EQUALS("", errout.str());
@ -6354,6 +6354,17 @@ private:
" return 0\n"
"}", NULL, false, false, false, false);
ASSERT_EQUALS("", errout.str());
// #4943 take care of C++11 initializer lists
check("std::vector<Foo> Bar() {\n"
" return\n"
" {\n"
" { \"1\" },\n"
" { \"2\" },\n"
" { \"3\" }\n"
" };\n"
"}", NULL, false, false, false, false);
ASSERT_EQUALS("", errout.str());
}
};