diff --git a/lib/checkother.cpp b/lib/checkother.cpp index ea1343042..03a4cd879 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1840,7 +1840,7 @@ void CheckOther::checkVariableScope() bool reduce = true; bool used = false; // Don't warn about unused variables for (; tok != var->scope()->classEnd; tok = tok->next()) { - if (tok->str() == "{" && tok->strAt(-1) != "=") { + if (tok->str() == "{" && tok->scope() != tok->previous()->scope()) { if (used) { bool used2 = false; if (!checkInnerScope(tok, var, used2) || used2) { diff --git a/test/testother.cpp b/test/testother.cpp index 8fea48b41..46f2f5b6d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -81,6 +81,7 @@ private: TEST_CASE(varScope18); TEST_CASE(varScope19); // Ticket #4994 TEST_CASE(varScope20); // Ticket #5103 + TEST_CASE(varScope21); // Ticket #5382 TEST_CASE(oldStylePointerCast); TEST_CASE(invalidPointerCast); @@ -1199,6 +1200,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void varScope21() { // Ticket #5382 - initializing two-dimensional array + varScope("int test() {\n" + " int test_value = 3;\n" + " int test_array[1][1] = { { test_value } };\n" + " return sizeof(test_array);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void checkOldStylePointerCast(const char code[]) { // Clear the error buffer.. errout.str("");