From 6485339d665a591d7907659a798c4751007fde13 Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Thu, 23 Jul 2015 09:41:35 +0200 Subject: [PATCH] Support lambdas in "else if" simplification (#6860) --- lib/tokenize.cpp | 5 +---- test/testsimplifytokens.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) 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)); + } }