SymbolDatabase: set proper valuetype for string addition result (#9161)

This commit is contained in:
Daniel Marjamäki 2020-12-01 20:16:39 +01:00
parent 9c20b29dba
commit 009ad11b3e
2 changed files with 13 additions and 0 deletions

View File

@ -5705,6 +5705,18 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
}
if (ternary || parent->isArithmeticalOp() || parent->tokType() == Token::eIncDecOp) {
// CONTAINER + pointer => CONTAINER
if (parent->str() == "+" && vt1 && vt1->type == ValueType::Type::CONTAINER && vt2 && vt2->pointer != 0) {
setValueType(parent, *vt1);
return;
}
// pointer + CONTAINER => CONTAINER
if (parent->str() == "+" && vt1 && vt1->pointer != 0U && vt2 && vt2->type == ValueType::Type::CONTAINER) {
setValueType(parent, *vt2);
return;
}
if (vt1->pointer != 0U && vt2 && vt2->pointer == 0U) {
setValueType(parent, *vt1);
return;

View File

@ -7140,6 +7140,7 @@ private:
ASSERT_EQUALS("container(test :: string)", typeOf("void foo(Vector<test::string> v) { for (auto s: v) { x=s+s; } }", "s", "test.cpp", &set));
ASSERT_EQUALS("container(test :: string)", typeOf("void foo(Vector<test::string> v) { for (auto s: v) { x=s+s; } }", "+", "test.cpp", &set));
ASSERT_EQUALS("container(test :: string)", typeOf("Vector<test::string> v; x = v.front();", "(", "test.cpp", &set));
ASSERT_EQUALS("container(test :: string)", typeOf("void foo(){test::string s; return \"x\"+s;}", "+", "test.cpp", &set));
}
// new