Merge pull request #2794 from pfultz2/lifetime-temp-ref-move

Fix issue 9888: False positive: Using reference to dangling temporary with std::move
This commit is contained in:
Daniel Marjamäki 2020-09-11 07:20:32 +02:00 committed by GitHub
commit 7e02789d3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 // std::move
if (vt2 && parent->str() == "(" && Token::simpleMatch(parent->tokAt(-3), "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; return;
} }
if (parent->str() == "*" && !parent->astOperand2() && valuetype.pointer > 0U) { if (parent->str() == "*" && !parent->astOperand2() && valuetype.pointer > 0U) {

View File

@ -1695,6 +1695,13 @@ private:
" std::cout << str_cref2 << std::endl;\n" " std::cout << str_cref2 << std::endl;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); 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() { void testglobalnamespace() {

View File

@ -6895,7 +6895,7 @@ private:
ASSERT_EQUALS("signed int", typeOf("int (*a)(int); a(5);", "( 5")); 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 )")); 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 // 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.. // struct member..
ASSERT_EQUALS("signed int", typeOf("struct AB { int a; int b; } ab; x = ab.a;", ".")); ASSERT_EQUALS("signed int", typeOf("struct AB { int a; int b; } ab; x = ab.a;", "."));