diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d68a0fee0..a45c27414 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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) diff --git a/test/testother.cpp b/test/testother.cpp index 792a47742..82233a0c7 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6345,7 +6345,7 @@ private: check("int fun(int a) {\n" " if (a < 0)\n" - " return a::b;\n" + " return c::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 Bar() {\n" + " return\n" + " {\n" + " { \"1\" },\n" + " { \"2\" },\n" + " { \"3\" }\n" + " };\n" + "}", NULL, false, false, false, false); + ASSERT_EQUALS("", errout.str()); } };