Fixed #676 (The scope of variable can actually not be limited)

This commit is contained in:
Daniel Marjamäki 2009-09-17 21:05:12 +02:00
parent 1dc738b1ae
commit e4291a5966
2 changed files with 17 additions and 1 deletions

View File

@ -594,7 +594,7 @@ void CheckOther::checkVariableScope()
continue;
// Variable declaration?
if (Token::Match(tok1, "%type% %var% ; %var% = %any% ;"))
if (Token::Match(tok1, "%type% %var% ; %var% = %num% ;"))
{
// Tokenizer modify "int i = 0;" to "int i; i = 0;",
// so to handle this situation we just skip

View File

@ -58,6 +58,7 @@ private:
TEST_CASE(varScope3);
TEST_CASE(varScope4);
TEST_CASE(varScope5);
TEST_CASE(varScope6);
TEST_CASE(nullpointer1);
TEST_CASE(nullpointer2);
@ -495,6 +496,21 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable i can be limited\n", errout.str());
}
void varScope6()
{
varScope("void f(int x)\n"
"{\n"
" int i = x;\n"
" if (a) {\n"
" x++;\n"
" }\n"
" if (b) {\n"
" c(i);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void checkNullPointer(const char code[])