Fix issue 10087: false positive: error: Reference to temporary returned. (#3205)
This commit is contained in:
parent
255f273c46
commit
5cf2f7e633
|
@ -4818,11 +4818,12 @@ static std::string getTypeString(const Token *typeToken)
|
||||||
while (Token::Match(typeToken, ":: %name%")) {
|
while (Token::Match(typeToken, ":: %name%")) {
|
||||||
ret += "::" + typeToken->strAt(1);
|
ret += "::" + typeToken->strAt(1);
|
||||||
typeToken = typeToken->tokAt(2);
|
typeToken = typeToken->tokAt(2);
|
||||||
}
|
if (typeToken->str() == "<") {
|
||||||
if (typeToken->str() == "<") {
|
for (const Token *tok = typeToken; tok != typeToken->link(); tok = tok->next())
|
||||||
for (const Token *tok = typeToken; tok != typeToken->link(); tok = tok->next())
|
ret += tok->str();
|
||||||
ret += tok->str();
|
ret += ">";
|
||||||
ret += ">";
|
typeToken = typeToken->link()->next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -6857,7 +6858,7 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
|
||||||
ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Variable *callVar, const Variable *funcVar)
|
ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Variable *callVar, const Variable *funcVar)
|
||||||
{
|
{
|
||||||
ValueType::MatchResult res = ValueType::matchParameter(call, funcVar->valueType());
|
ValueType::MatchResult res = ValueType::matchParameter(call, funcVar->valueType());
|
||||||
if (res == ValueType::MatchResult::SAME && callVar && call->container) {
|
if (callVar && ((res == ValueType::MatchResult::SAME && call->container) || res == ValueType::MatchResult::UNKNOWN)) {
|
||||||
const std::string type1 = getTypeString(callVar->typeStartToken());
|
const std::string type1 = getTypeString(callVar->typeStartToken());
|
||||||
const std::string type2 = getTypeString(funcVar->typeStartToken());
|
const std::string type2 = getTypeString(funcVar->typeStartToken());
|
||||||
if (type1 != type2)
|
if (type1 != type2)
|
||||||
|
|
|
@ -407,6 +407,7 @@ private:
|
||||||
TEST_CASE(findFunction40); // #10135
|
TEST_CASE(findFunction40); // #10135
|
||||||
TEST_CASE(findFunction41); // #10202
|
TEST_CASE(findFunction41); // #10202
|
||||||
TEST_CASE(findFunction42);
|
TEST_CASE(findFunction42);
|
||||||
|
TEST_CASE(findFunction43); // #10087
|
||||||
TEST_CASE(findFunctionContainer);
|
TEST_CASE(findFunctionContainer);
|
||||||
TEST_CASE(findFunctionExternC);
|
TEST_CASE(findFunctionExternC);
|
||||||
TEST_CASE(findFunctionGlobalScope); // ::foo
|
TEST_CASE(findFunctionGlobalScope); // ::foo
|
||||||
|
@ -6425,6 +6426,34 @@ private:
|
||||||
ASSERT_EQUALS(2, functok->function()->tokenDef->linenr());
|
ASSERT_EQUALS(2, functok->function()->tokenDef->linenr());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void findFunction43() { // #10087
|
||||||
|
{
|
||||||
|
GET_SYMBOL_DB("struct A {};\n"
|
||||||
|
"const A* g(const std::string&);\n"
|
||||||
|
"const A& g(std::vector<A>::size_type i);\n"
|
||||||
|
"const A& f(std::vector<A>::size_type i) { return g(i); }\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "g ( i )");
|
||||||
|
ASSERT(functok);
|
||||||
|
ASSERT(functok->function());
|
||||||
|
ASSERT(functok->function()->name() == "g");
|
||||||
|
ASSERT_EQUALS(3, functok->function()->tokenDef->linenr());
|
||||||
|
}
|
||||||
|
{
|
||||||
|
GET_SYMBOL_DB("struct A {};\n"
|
||||||
|
"const A& g(std::vector<A>::size_type i);\n"
|
||||||
|
"const A* g(const std::string&);\n"
|
||||||
|
"const A& f(std::vector<A>::size_type i) { return g(i); }\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
const Token *functok = Token::findsimplematch(tokenizer.tokens(), "g ( i )");
|
||||||
|
ASSERT(functok);
|
||||||
|
ASSERT(functok->function());
|
||||||
|
ASSERT(functok->function()->name() == "g");
|
||||||
|
ASSERT_EQUALS(2, functok->function()->tokenDef->linenr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void findFunctionContainer() {
|
void findFunctionContainer() {
|
||||||
{
|
{
|
||||||
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
|
GET_SYMBOL_DB("void dostuff(std::vector<int> v);\n"
|
||||||
|
|
Loading…
Reference in New Issue