Fixed #2084 (False positive: object destroyed immediately (struct and function with same name))
Tightened up class definition matching so as not to match C-style struct tags.
This commit is contained in:
parent
a58094e827
commit
fbd3d92aa9
|
@ -3884,8 +3884,8 @@ bool CheckOther::isIdentifierObjectType(const Token * const tok)
|
||||||
return found->second;
|
return found->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string classDef = std::string("class|struct ") + identifier;
|
const std::string classDefnOrDecl = std::string("class|struct ") + identifier + " [{:;]";
|
||||||
const bool result = Token::findmatch(_tokenizer->tokens(), classDef.c_str());
|
const bool result = Token::findmatch(_tokenizer->tokens(), classDefnOrDecl.c_str());
|
||||||
isClassResults.insert(std::make_pair(identifier, result));
|
isClassResults.insert(std::make_pair(identifier, result));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -3893,6 +3893,7 @@ bool CheckOther::isIdentifierObjectType(const Token * const tok)
|
||||||
|
|
||||||
void CheckOther::checkMisusedScopedObject()
|
void CheckOther::checkMisusedScopedObject()
|
||||||
{
|
{
|
||||||
|
const char localClassDefinition[] = "class|struct %var% [{:]";
|
||||||
bool withinFunction = false;
|
bool withinFunction = false;
|
||||||
unsigned int depth = 0;
|
unsigned int depth = 0;
|
||||||
std::string className = "";
|
std::string className = "";
|
||||||
|
@ -3917,7 +3918,7 @@ void CheckOther::checkMisusedScopedObject()
|
||||||
className.clear();
|
className.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (Token::Match(tok, "class|struct"))
|
else if (Token::Match(tok, localClassDefinition))
|
||||||
{
|
{
|
||||||
className = tok->strAt(1);
|
className = tok->strAt(1);
|
||||||
isClassResults.insert(std::make_pair(className, false));
|
isClassResults.insert(std::make_pair(className, false));
|
||||||
|
|
|
@ -115,6 +115,7 @@ private:
|
||||||
TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);
|
TEST_CASE(testMisusedScopeObjectDoesNotPickLocalClassConstructors);
|
||||||
TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);
|
TEST_CASE(testMisusedScopeObjectDoesNotPickUsedObject);
|
||||||
TEST_CASE(trac2071);
|
TEST_CASE(trac2071);
|
||||||
|
TEST_CASE(trac2084);
|
||||||
|
|
||||||
TEST_CASE(assignmentInAssert);
|
TEST_CASE(assignmentInAssert);
|
||||||
}
|
}
|
||||||
|
@ -3160,6 +3161,21 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trac2084()
|
||||||
|
{
|
||||||
|
check("#include <signal.h>\n"
|
||||||
|
"\n"
|
||||||
|
"void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" struct sigaction sa;\n"
|
||||||
|
"\n"
|
||||||
|
" { sigaction(SIGHUP, &sa, 0); };\n"
|
||||||
|
" { sigaction(SIGINT, &sa, 0); };\n"
|
||||||
|
"}\n"
|
||||||
|
);
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void trac2071()
|
void trac2071()
|
||||||
{
|
{
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
|
|
Loading…
Reference in New Issue