SymbolDatabase: Improved types for 'std::string + x'

This commit is contained in:
Daniel Marjamäki 2020-12-05 13:24:21 +01:00
parent dffa40803e
commit cb7eee2aa9
2 changed files with 8 additions and 5 deletions

View File

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

View File

@ -7141,6 +7141,9 @@ private:
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));
ASSERT_EQUALS("container(test :: string)", typeOf("void foo(){test::string s; return s+\"x\";}", "+", "test.cpp", &set));
ASSERT_EQUALS("container(test :: string)", typeOf("void foo(){test::string s; return 'x'+s;}", "+", "test.cpp", &set));
ASSERT_EQUALS("container(test :: string)", typeOf("void foo(){test::string s; return s+'x';}", "+", "test.cpp", &set));
}
// new