From c52460929fc20d647df7adcd0454ffd3ce9520d2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Feb 2026 09:19:00 +0100 Subject: [PATCH 1/5] Update tokenize.cpp --- lib/tokenize.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d0e46b54542..bb3957fb9ae 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7964,8 +7964,8 @@ void Tokenizer::elseif() if (Token::Match(tok2, "}|;")) { if (tok2->next() && tok2->strAt(1) != "else") { - tok->insertToken("{"); - tok2->insertToken("}"); + tok->insertToken("{")->isSimplifiedScope(true); + tok2->insertToken("}")->isSimplifiedScope(true); Token::createMutualLinks(tok->next(), tok2->next()); break; } From 4be28f0f58a3878b6a71c736200ce2261cda26f0 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Feb 2026 09:20:49 +0100 Subject: [PATCH 2/5] Update checkother.cpp --- lib/checkother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index d045fb142c8..98982ec918d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1290,7 +1290,7 @@ void CheckOther::checkVariableScope() tok = tok->link(); // parse else if blocks.. - } else if (Token::simpleMatch(tok, "else { if (") && Token::simpleMatch(tok->linkAt(3), ") {")) { + } else if (Token::simpleMatch(tok, "else { if (") && tok->next()->isSimplifiedScope() && Token::simpleMatch(tok->linkAt(3), ") {")) { tok = tok->next(); } else if (tok->varId() == var->declarationId() || tok->str() == "goto") { reduce = false; From c1fc2d81077d906663fb5be9b920316566753b93 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Feb 2026 09:36:04 +0100 Subject: [PATCH 3/5] Update testother.cpp --- test/testother.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index fadb61426a4..de5e5181853 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -121,6 +121,7 @@ class TestOther : public TestFixture { TEST_CASE(varScope41); // #11845 TEST_CASE(varScope42); TEST_CASE(varScope43); + TEST_CASE(varScope45); TEST_CASE(oldStylePointerCast); TEST_CASE(intToPointerCast); @@ -1945,6 +1946,17 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); } + varScope45() { + check("void g(int x, int y) {\n" // #14497 + " int a = x, b = y;\n" + " if (a) {}\n" + " else {\n" + " if (b) {}\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2:16]: (style) The scope of the variable 'b' can be reduced. [variableScope]\n", errout_str()); + } + #define checkOldStylePointerCast(...) checkOldStylePointerCast_(__FILE__, __LINE__, __VA_ARGS__) template void checkOldStylePointerCast_(const char* file, int line, const char (&code)[size], Standards::cppstd_t std = Standards::CPPLatest) { From 7dde7e4abacf2322cb1f673a2014ae375cebae48 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 17 Feb 2026 09:42:40 +0100 Subject: [PATCH 4/5] Update testother.cpp --- test/testother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index de5e5181853..5dc449ecac2 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1946,7 +1946,7 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:3:12]: (style) The scope of the variable 'x' can be reduced. [variableScope]\n", errout_str()); } - varScope45() { + void varScope45() { check("void g(int x, int y) {\n" // #14497 " int a = x, b = y;\n" " if (a) {}\n" From 8f2c02d8f0c3bf196be16f32bff85ebbcf1b5671 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:50:03 +0100 Subject: [PATCH 5/5] Update testother.cpp --- test/testother.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/testother.cpp b/test/testother.cpp index cf6f5ccf4bb..06512a930c9 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1971,7 +1971,8 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:2:11]: (style) The scope of the variable 'p' can be reduced. [variableScope]\n" "[test.cpp:12:11]: (style) The scope of the variable 'q' can be reduced. [variableScope]\n", errout_str()); - + } + void varScope45() { check("void g(int x, int y) {\n" // #14497 " int a = x, b = y;\n"