Fixed #5382: False positive "scope can be reduced" when initializing two-dimensional array.

This commit is contained in:
PKEuS 2014-03-17 12:34:39 +01:00
parent d325d14b11
commit ebd0b43c4f
2 changed files with 11 additions and 1 deletions

View File

@ -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) {

View File

@ -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("");