From 475e456a4484689e6d80ab1ce2223789c288aebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 12 Jun 2025 16:33:37 +0200 Subject: [PATCH 1/2] add test --- test/testtokenize.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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; } };")); From 618354c498a3e39fbd228d8dc5d73a948e86df46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 12 Jun 2025 10:56:26 +0200 Subject: [PATCH 2/2] fix #12302 --- lib/tokenlist.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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);