diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 0258d12f9e0..2f51bfef8d2 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -470,7 +470,7 @@ static bool iscast(const Token *tok, bool cpp) if (Token::Match(tok->link(), ") %assign%|,|...")) return false; - if (tok->previous() && tok->previous()->isName() && tok->strAt(-1) != "return" && + if (tok->previous() && tok->previous()->isName() && !Token::Match(tok->previous(), "return|case") && (!cpp || !Token::Match(tok->previous(), "delete|throw"))) return false; @@ -600,6 +600,10 @@ static bool iscpp11init_impl(const Token * const tok) if (Token::simpleMatch(castTok->astParent(), "case")) return true; } + if (findParent(colonTok->previous(), [](const Token *parent){ + return parent->str() == "case"; + })) + return true; const Token* caseTok = colonTok->tokAt(-2); while (caseTok && Token::Match(caseTok->tokAt(-1), "::|%name%")) caseTok = caseTok->tokAt(-1); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 26b0ded675b..6f529ae41f2 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7071,6 +7071,23 @@ class TestTokenizer : public TestFixture { "}\n")); ASSERT_EQUALS("", errout_str()); + ASSERT_NO_THROW(tokenizeAndStringify("int foo() {\n" + " connect([]( const int& f ) {\n" + " switch( f )\n" + " {\n" + " case (int)1:\n" + " {\n" + " A r(f);\n" + " if (1) {}\n" + " }\n" + " break;\n" + " }\n" + " return 0;\n" + " });\n" + " return 0;\n" + "}\n")); + ASSERT_EQUALS("", errout_str()); + // #11378 ASSERT_EQUALS("gT{(&[{= 0return", testAst("auto g = T{ [&]() noexcept -> int { return 0; } };"));