Added test for functor false-positive [passing]
Also removed typedef's following danmar's review and renamed isClassresults -> isClassResults to make more clear.
This commit is contained in:
parent
19d67757b1
commit
0017655f55
|
@ -3845,15 +3845,16 @@ void CheckOther::checkMathFunctions()
|
|||
bool CheckOther::isIdentifierObjectType(const Token * const tok)
|
||||
{
|
||||
const std::string identifier = tok->tokAt(1)->str();
|
||||
const MemoizeIsClassResultsIterator found = isClassresults.find(identifier);
|
||||
if (found != isClassresults.end())
|
||||
|
||||
const std::map<std::string, bool>::const_iterator found = isClassResults.find(identifier);
|
||||
if (found != isClassResults.end())
|
||||
{
|
||||
return found->second;
|
||||
}
|
||||
|
||||
const std::string classDef = std::string("class|struct ") + identifier;
|
||||
const bool result = Token::findmatch(_tokenizer->tokens(), classDef.c_str());
|
||||
isClassresults.insert(std::make_pair(identifier, result));
|
||||
isClassResults.insert(std::make_pair(identifier, result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -352,9 +352,7 @@ private:
|
|||
*/
|
||||
bool isIdentifierObjectType(const Token* const tok);
|
||||
|
||||
typedef std::map<std::string, bool> MemoizeIsClassResults;
|
||||
typedef MemoizeIsClassResults::const_iterator MemoizeIsClassResultsIterator;
|
||||
MemoizeIsClassResults isClassresults;
|
||||
std::map<std::string, bool> isClassResults;
|
||||
};
|
||||
/// @}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -111,6 +111,7 @@ private:
|
|||
TEST_CASE(testMisusedScopeObjectPicksStruct);
|
||||
TEST_CASE(testMisusedScopeObjectDoesNotPickIf);
|
||||
TEST_CASE(testMisusedScopeObjectDoesNotPickConstructorDeclaration);
|
||||
TEST_CASE(testMisusedScopeObjectDoesNotPickFunctor);
|
||||
}
|
||||
|
||||
void check(const char code[])
|
||||
|
@ -3100,6 +3101,31 @@ private:
|
|||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void testMisusedScopeObjectDoesNotPickFunctor()
|
||||
{
|
||||
check("\n"
|
||||
"#include <algorithm>\n"
|
||||
"\n"
|
||||
"class IncrementFunctor\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" void operator()(int &i)\n"
|
||||
" {\n"
|
||||
" ++i;\n"
|
||||
" }\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"int main()\n"
|
||||
"{\n"
|
||||
" int a[] = {1, 2, 3, 4, 5};\n"
|
||||
" const size_t n = sizeof a / sizeof a[0];\n"
|
||||
" std::for_each(a, a + n, IncrementFunctor());\n"
|
||||
" return a[0];\n"
|
||||
"}\n"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestOther)
|
||||
|
|
Loading…
Reference in New Issue