diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d070daae8..911a64255 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6899,12 +6899,9 @@ bool Tokenizer::simplifyKnownVariablesSimplify(Token **tok2, Token *tok3, unsign void Tokenizer::elseif() { for (Token *tok = list.front(); tok; tok = tok->next()) { - if (Token::Match(tok, "(|[") || - (tok->str() == "{" && tok->previous() && tok->previous()->str() == "=")) - tok = tok->link(); - if (!Token::simpleMatch(tok, "else if")) continue; + for (Token *tok2 = tok; tok2; tok2 = tok2->next()) { if (Token::Match(tok2, "(|{|[")) tok2 = tok2->link(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 5e4a68b3f..7a5419516 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -833,6 +833,23 @@ private: "}"; ASSERT_EQUALS(tok(expected), tok(src)); } + + // Ticket #6860 - lambdas + { + const char src[] = "( []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() )"; + const char expected[] = "\n\n##file 0\n1: ( [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) )\n"; + ASSERT_EQUALS(expected, elseif(src)); + } + { + const char src[] = "[ []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() ]"; + const char expected[] = "\n\n##file 0\n1: [ [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) ]\n"; + ASSERT_EQUALS(expected, elseif(src)); + } + { + const char src[] = "= { []{if (ab) {cd}else if(ef) { gh } else { ij }kl}() }"; + const char expected[] = "\n\n##file 0\n1: = { [ ] { if ( ab ) { cd } else { if ( ef ) { gh } else { ij } } kl } ( ) }\n"; + ASSERT_EQUALS(expected, elseif(src)); + } }