diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index becb5a439..01323d986 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4373,7 +4373,7 @@ void Tokenizer::removeRedundantFor() void Tokenizer::removeRedundantSemicolons() { for (Token *tok = list.front(); tok; tok = tok->next()) { - if (tok->str() == "(") { + if (tok->link() && tok->str() == "(") { tok = tok->link(); continue; } diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index a7787086d..7c26f0620 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -194,6 +194,7 @@ private: TEST_CASE(garbageCode143); // #6922 TEST_CASE(garbageCode144); // #6865 TEST_CASE(garbageCode145); // #7074 + TEST_CASE(garbageCode146); // #7081 TEST_CASE(garbageValueFlow); TEST_CASE(garbageSymbolDatabase); @@ -1143,6 +1144,13 @@ private: checkCode("++4++ + + E++++++++++ + ch " "tp.oed5[.]"); } + void garbageCode146() { // #7081 + ASSERT_THROW(checkCode("void foo() {\n" + " ? std::cout << pow((, 1) << std::endl;\n" + " double