Fixed #5382: False positive "scope can be reduced" when initializing two-dimensional array.
This commit is contained in:
parent
d325d14b11
commit
ebd0b43c4f
|
@ -1840,7 +1840,7 @@ void CheckOther::checkVariableScope()
|
||||||
bool reduce = true;
|
bool reduce = true;
|
||||||
bool used = false; // Don't warn about unused variables
|
bool used = false; // Don't warn about unused variables
|
||||||
for (; tok != var->scope()->classEnd; tok = tok->next()) {
|
for (; tok != var->scope()->classEnd; tok = tok->next()) {
|
||||||
if (tok->str() == "{" && tok->strAt(-1) != "=") {
|
if (tok->str() == "{" && tok->scope() != tok->previous()->scope()) {
|
||||||
if (used) {
|
if (used) {
|
||||||
bool used2 = false;
|
bool used2 = false;
|
||||||
if (!checkInnerScope(tok, var, used2) || used2) {
|
if (!checkInnerScope(tok, var, used2) || used2) {
|
||||||
|
|
|
@ -81,6 +81,7 @@ private:
|
||||||
TEST_CASE(varScope18);
|
TEST_CASE(varScope18);
|
||||||
TEST_CASE(varScope19); // Ticket #4994
|
TEST_CASE(varScope19); // Ticket #4994
|
||||||
TEST_CASE(varScope20); // Ticket #5103
|
TEST_CASE(varScope20); // Ticket #5103
|
||||||
|
TEST_CASE(varScope21); // Ticket #5382
|
||||||
|
|
||||||
TEST_CASE(oldStylePointerCast);
|
TEST_CASE(oldStylePointerCast);
|
||||||
TEST_CASE(invalidPointerCast);
|
TEST_CASE(invalidPointerCast);
|
||||||
|
@ -1199,6 +1200,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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[]) {
|
void checkOldStylePointerCast(const char code[]) {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
Loading…
Reference in New Issue