Fix issue 9888: False positive: Using reference to dangling temporary with std::move

This commit is contained in:
Paul 2020-09-10 22:38:31 -05:00
parent 2b12ef653d
commit b26c581556
3 changed files with 11 additions and 2 deletions

View File

@ -5468,7 +5468,9 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
}
// std::move
if (vt2 && parent->str() == "(" && Token::simpleMatch(parent->tokAt(-3), "std :: move (")) {
setValueType(parent, valuetype);
ValueType vt = valuetype;
vt.reference = Reference::RValue;
setValueType(parent, vt);
return;
}
if (parent->str() == "*" && !parent->astOperand2() && valuetype.pointer > 0U) {

View File

@ -1695,6 +1695,13 @@ private:
" std::cout << str_cref2 << std::endl;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("char f() {\n"
" char c = 0;\n"
" char&& cr = std::move(c);\n"
" return cr;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void testglobalnamespace() {

View File

@ -6895,7 +6895,7 @@ private:
ASSERT_EQUALS("signed int", typeOf("int (*a)(int); a(5);", "( 5"));
ASSERT_EQUALS("s", typeOf("struct s { s foo(); s(int, int); }; s s::foo() { return s(1, 2); } ", "( 1 , 2 )"));
// Some standard template functions.. TODO library configuration
ASSERT_EQUALS("signed int", typeOf("std::move(5);", "( 5 )"));
ASSERT_EQUALS("signed int &&", typeOf("std::move(5);", "( 5 )"));
// struct member..
ASSERT_EQUALS("signed int", typeOf("struct AB { int a; int b; } ab; x = ab.a;", "."));