diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fd4ab59c9..2ecb7fdc4 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4312,7 +4312,7 @@ bool Tokenizer::simplifyQuestionMark() { if (endTok->str() == ";") { - Token::eraseTokens(semicolon->previous(), endTok->next()); + Token::eraseTokens(semicolon->previous(), endTok); ret = true; break; } diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index cdfe00c3f..0e12833bf 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -67,6 +67,7 @@ private: TEST_CASE(localvar19); // ticket #1776 TEST_CASE(localvar20); // ticket #1799 TEST_CASE(localvar21); // ticket #1807 + TEST_CASE(localvar22); // ticket #1811 TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias3); // ticket #1639 @@ -1190,6 +1191,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void localvar22() // ticket #1811 + { + functionVariableUsage("int foo(int u, int v)\n" + "{\n" + " int h, i;\n" + " h = 0 ? u : v;\n" + " i = 1 ? u : v;\n" + " return h + i;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void localvaralias1() { functionVariableUsage("void foo()\n"