add support for using global qualified :: memset on class and class member initialization
This commit is contained in:
parent
2516aad31d
commit
ac6d67dc4d
|
@ -331,7 +331,7 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
|
||||||
ftok = ftok->tokAt(2);
|
ftok = ftok->tokAt(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Token::Match(ftok->next(), "%var%") &&
|
if (!Token::Match(ftok->next(), "::| %var%") &&
|
||||||
!Token::Match(ftok->next(), "this . %var%") &&
|
!Token::Match(ftok->next(), "this . %var%") &&
|
||||||
!Token::Match(ftok->next(), "* %var% =") &&
|
!Token::Match(ftok->next(), "* %var% =") &&
|
||||||
!Token::Match(ftok->next(), "( * this ) . %var%"))
|
!Token::Match(ftok->next(), "( * this ) . %var%"))
|
||||||
|
@ -355,17 +355,18 @@ void CheckClass::initializeVarList(const Function &func, std::list<std::string>
|
||||||
ftok = ftok->tokAt(2);
|
ftok = ftok->tokAt(2);
|
||||||
|
|
||||||
// Clearing all variables..
|
// Clearing all variables..
|
||||||
if (Token::simpleMatch(ftok, "memset ( this ,"))
|
if (Token::Match(ftok, "::| memset ( this ,"))
|
||||||
{
|
{
|
||||||
assignAllVar(usage);
|
assignAllVar(usage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clearing array..
|
// Clearing array..
|
||||||
else if (Token::Match(ftok, "memset ( %var% ,"))
|
else if (Token::Match(ftok, "::| memset ( %var% ,"))
|
||||||
{
|
{
|
||||||
assignVar(ftok->strAt(2), scope, usage);
|
const int offset = ftok->str() == "::" ? 1 : 0;
|
||||||
ftok = ftok->next()->link();
|
assignVar(ftok->strAt(2 + offset), scope, usage);
|
||||||
|
ftok = ftok->tokAt(1 + offset)->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ private:
|
||||||
TEST_CASE(uninitVarArray4);
|
TEST_CASE(uninitVarArray4);
|
||||||
TEST_CASE(uninitVarArray5);
|
TEST_CASE(uninitVarArray5);
|
||||||
TEST_CASE(uninitVarArray6);
|
TEST_CASE(uninitVarArray6);
|
||||||
|
TEST_CASE(uninitVarArray7);
|
||||||
TEST_CASE(uninitVarArray2D);
|
TEST_CASE(uninitVarArray2D);
|
||||||
TEST_CASE(uninitVarStruct1); // ticket #2172
|
TEST_CASE(uninitVarStruct1); // ticket #2172
|
||||||
TEST_CASE(uninitVarStruct2); // ticket #838
|
TEST_CASE(uninitVarStruct2); // ticket #838
|
||||||
|
@ -2395,6 +2396,33 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uninitVarArray7()
|
||||||
|
{
|
||||||
|
checkUninitVar("class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
" int array[10];\n"
|
||||||
|
"public:\n"
|
||||||
|
" Foo() { }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Foo::array' is not initialized in the constructor.\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
" int array[10];\n"
|
||||||
|
"public:\n"
|
||||||
|
" Foo() { memset(array, 0, sizeof(array)); }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
" int array[10];\n"
|
||||||
|
"public:\n"
|
||||||
|
" Foo() { ::memset(array, 0, sizeof(array)); }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void uninitVarArray2D()
|
void uninitVarArray2D()
|
||||||
{
|
{
|
||||||
checkUninitVar("class John\n"
|
checkUninitVar("class John\n"
|
||||||
|
@ -2616,6 +2644,15 @@ private:
|
||||||
"};\n");
|
"};\n");
|
||||||
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("class Foo\n"
|
||||||
|
"{\n"
|
||||||
|
"public:\n"
|
||||||
|
" int * pointer;\n"
|
||||||
|
" Foo() { ::memset(this, 0, sizeof(*this)); }\n"
|
||||||
|
"};\n");
|
||||||
|
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void privateCtor1()
|
void privateCtor1()
|
||||||
|
|
Loading…
Reference in New Issue