Fix FP unusedStructMember with std::map (#4899)
This commit is contained in:
parent
3d965b5b81
commit
6316479782
|
@ -1226,6 +1226,9 @@ bool Library::isContainerYield(const Token * const cond, Library::Container::Yie
|
||||||
// returns true if ftok is not a library function
|
// returns true if ftok is not a library function
|
||||||
bool Library::isNotLibraryFunction(const Token *ftok) const
|
bool Library::isNotLibraryFunction(const Token *ftok) const
|
||||||
{
|
{
|
||||||
|
if (ftok->isKeyword() || ftok->isStandardType())
|
||||||
|
return true;
|
||||||
|
|
||||||
if (ftok->function() && ftok->function()->nestedIn && ftok->function()->nestedIn->type != Scope::eGlobal)
|
if (ftok->function() && ftok->function()->nestedIn && ftok->function()->nestedIn->type != Scope::eGlobal)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -1278,13 +1278,12 @@ void SymbolDatabase::createSymbolDatabaseSetVariablePointers()
|
||||||
const Variable *membervar = classScope ? classScope->getVariable(membertok->str()) : nullptr;
|
const Variable *membervar = classScope ? classScope->getVariable(membertok->str()) : nullptr;
|
||||||
setMemberVar(membervar, membertok, tok);
|
setMemberVar(membervar, membertok, tok);
|
||||||
} else if (tok->valueType() && tok->valueType()->type == ValueType::CONTAINER) {
|
} else if (tok->valueType() && tok->valueType()->type == ValueType::CONTAINER) {
|
||||||
if (Token::Match(var->typeStartToken(), "std :: %type% < %name%")) {
|
if (const Token* ctt = tok->valueType()->containerTypeToken) {
|
||||||
const Token* type2tok = var->typeStartToken()->tokAt(4);
|
while (ctt && ctt->isKeyword())
|
||||||
while (type2tok && type2tok->isKeyword())
|
ctt = ctt->next();
|
||||||
type2tok = type2tok->next();
|
const Type* ct = findTypeInNested(ctt, tok->scope());
|
||||||
const Type* type2 = type2tok ? type2tok->type() : nullptr;
|
if (ct && ct->classScope && ct->classScope->definedType) {
|
||||||
if (type2 && type2->classScope && type2->classScope->definedType) {
|
const Variable *membervar = ct->classScope->getVariable(membertok->str());
|
||||||
const Variable *membervar = type2->classScope->getVariable(membertok->str());
|
|
||||||
setMemberVar(membervar, membertok, tok);
|
setMemberVar(membervar, membertok, tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ private:
|
||||||
TEST_CASE(structmember20); // #10737
|
TEST_CASE(structmember20); // #10737
|
||||||
TEST_CASE(structmember21); // #4759
|
TEST_CASE(structmember21); // #4759
|
||||||
TEST_CASE(structmember22); // #11016
|
TEST_CASE(structmember22); // #11016
|
||||||
|
TEST_CASE(structmember23);
|
||||||
|
|
||||||
TEST_CASE(localvar1);
|
TEST_CASE(localvar1);
|
||||||
TEST_CASE(localvar2);
|
TEST_CASE(localvar2);
|
||||||
|
@ -1846,6 +1847,17 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void structmember23() {
|
||||||
|
checkStructMemberUsage("namespace N {\n"
|
||||||
|
" struct S { std::string s; };\n"
|
||||||
|
"}\n"
|
||||||
|
"std::string f() {\n"
|
||||||
|
" std::map<int, N::S> m = { { 0, { \"abc\" } } };\n"
|
||||||
|
" return m[0].s;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void functionVariableUsage_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
void functionVariableUsage_(const char* file, int line, const char code[], const char filename[] = "test.cpp") {
|
||||||
// Clear the error buffer..
|
// Clear the error buffer..
|
||||||
errout.str("");
|
errout.str("");
|
||||||
|
|
Loading…
Reference in New Issue