@@ -101,6 +101,8 @@ class TestOther : public TestFixture {
101101 TEST_CASE (varScope33);
102102 TEST_CASE (varScope34);
103103 TEST_CASE (varScope35);
104+ TEST_CASE (varScope36); // #12158
105+ TEST_CASE (varScope37); // #12158
104106
105107 TEST_CASE (oldStylePointerCast);
106108 TEST_CASE (invalidPointerCast);
@@ -1667,6 +1669,35 @@ class TestOther : public TestFixture {
16671669 ASSERT_EQUALS (" [test.cpp:4]: (style) The scope of the variable 'buf' can be reduced.\n " , errout.str ());
16681670 }
16691671
1672+ void varScope36 () {
1673+ // #12158
1674+ check (" void f( uint32_t value ) {\n "
1675+ " uint32_t i = 0U;\n "
1676+ " if ( value > 100U ) { }\n "
1677+ " else if( value > 50U ) { }\n "
1678+ " else{\n "
1679+ " for( i = 0U; i < 5U; i++ ) {}\n "
1680+ " }\n "
1681+ " }\n " , nullptr , false );
1682+ ASSERT_EQUALS (" [test.cpp:2]: (style) The scope of the variable 'i' can be reduced.\n " , errout.str ());
1683+ }
1684+
1685+ void varScope37 () {
1686+ // #12158
1687+ check (" void f( uint32_t value ) {\n "
1688+ " uint32_t i = 0U;\n "
1689+ " if ( value > 100U ) { }\n "
1690+ " else {\n "
1691+ " if( value > 50U ) { }\n "
1692+ " else{\n "
1693+ " for( i = 0U; i < 5U; i++ ) {}\n "
1694+ " }\n "
1695+ " }\n "
1696+ " }\n " , nullptr , false );
1697+ ASSERT_EQUALS (" [test.cpp:2]: (style) The scope of the variable 'i' can be reduced.\n " , errout.str ());
1698+ }
1699+
1700+
16701701#define checkOldStylePointerCast (code ) checkOldStylePointerCast_(code, __FILE__, __LINE__)
16711702 void checkOldStylePointerCast_ (const char code[], const char * file, int line) {
16721703 // Clear the error buffer..
0 commit comments