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

@ -1881,33 +1881,16 @@ void CheckOther::checkCommaSeparatedReturn()
if (!_settings->isEnabled("style"))
return;
for (const Token *tok = _tokenizer->tokens(); tok ; tok = tok->next()) {
if (Token::Match(tok ,"return")) {
while (tok && tok->str() != ";") {
if (tok->str() == "(")
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;
}
}
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (tok->str() == "return") {
while (tok && tok->str() != ";") {
if (Token::Match(tok, "[([{<]") && tok->link())
tok = tok->link();
if (!tok->isExpandedMacro() && tok->str() == "," && tok->linenr() != tok->next()->linenr())
commaSeparatedReturnError(tok);
tok=tok->next();
tok = tok->next();
}
// bailout: missing semicolon (invalid code / bad tokenizer)
if (!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());
}
};