fix #2928 (False positive (static variable misinterpreted as auto variable))

This commit is contained in:
Robert Reif 2011-07-21 18:20:19 -04:00
parent fe1ba6ae37
commit cc1ecccd01
3 changed files with 15 additions and 4 deletions

View File

@ -16,9 +16,9 @@ ifeq ($(HAVE_RULES),yes)
endif endif
endif endif
ifndef CXX #ifndef CXX
CXX=g++ CXX=clang++
endif #endif
ifndef PREFIX ifndef PREFIX
PREFIX=/usr PREFIX=/usr

View File

@ -107,7 +107,7 @@ void CheckAutoVariables::autoVariables()
if (var1 && var1->isArgument() && Token::Match(var1->nameToken()->tokAt(-3), "%type% * *")) if (var1 && var1->isArgument() && Token::Match(var1->nameToken()->tokAt(-3), "%type% * *"))
{ {
const Variable * var2 = symbolDatabase->getVariableFromVarId(tok->tokAt(4)->varId()); const Variable * var2 = symbolDatabase->getVariableFromVarId(tok->tokAt(4)->varId());
if (var2 && var2->isLocal() && var2->isArray()) if (var2 && var2->isLocal() && var2->isArray() && !var2->isStatic())
errorAutoVariableAssignment(tok); errorAutoVariableAssignment(tok);
} }
tok = tok->tokAt(4); tok = tok->tokAt(4);

View File

@ -70,6 +70,7 @@ private:
TEST_CASE(testautovar1); TEST_CASE(testautovar1);
TEST_CASE(testautovar2); TEST_CASE(testautovar2);
TEST_CASE(testautovar3); // ticket #2925 TEST_CASE(testautovar3); // ticket #2925
TEST_CASE(testautovar4); // ticket #2928
TEST_CASE(testautovar_array1); TEST_CASE(testautovar_array1);
TEST_CASE(testautovar_array2); TEST_CASE(testautovar_array2);
TEST_CASE(testautovar_return1); TEST_CASE(testautovar_return1);
@ -164,6 +165,16 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str()); ASSERT_EQUALS("[test.cpp:3]: (error) Assigning address of local auto-variable to a function parameter.\n", errout.str());
} }
void testautovar4() // ticket #2928
{
check("void foo(int **p)\n"
"{\n"
" static int x[100];\n"
" *p = x;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void testautovar_array1() void testautovar_array1()
{ {
check("void func1(int* arr[2])\n" check("void func1(int* arr[2])\n"