Merge pull request #2731 from pfultz2/dangling-container-value-type

Fix issue 9770: FP returnDanglingLifetime for class method taking const char* and returning std::string
This commit is contained in:
Daniel Marjamäki 2020-08-06 09:02:54 +02:00 committed by GitHub
commit 4fabd1e059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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() {