Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; } };"));

Expand Down
Loading