Fix issue 9770: FP returnDanglingLifetime for class method taking const char* and returning std::string

This commit is contained in:
Paul 2020-08-05 23:17:35 -05:00
parent 72fa5f2e27
commit 0cc1f69862
2 changed files with 11 additions and 1 deletions

View File

@ -3068,7 +3068,7 @@ static bool isLifetimeBorrowed(const ValueType *vt, const ValueType *vtParent)
return false;
if (!vt)
return false;
if (vt->type != ValueType::UNKNOWN_TYPE && vtParent->type != ValueType::UNKNOWN_TYPE) {
if (vt->type != ValueType::UNKNOWN_TYPE && vtParent->type != ValueType::UNKNOWN_TYPE && vtParent->container == vt->container) {
if (vtParent->pointer > vt->pointer)
return true;
if (vtParent->pointer < vt->pointer && vtParent->isIntegral())

View File

@ -2328,6 +2328,16 @@ private:
" return value;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #9770
check("class C {\n"
" std::string f(const char*);\n"
"};\n"
"std::string C::f(const char*) {\n"
" const char data[] = \"x\";\n"
" return data;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void danglingLifetimeFunction() {