Fix #10469 FP returnTempReference with overloaded operator+= (#3678)

This commit is contained in:
chrchr-github 2022-01-12 22:05:30 +01:00 committed by GitHub
parent fa651272f0
commit 1b89c998f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -7092,7 +7092,14 @@ ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Va
ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Variable *callVar, const Variable *funcVar) ValueType::MatchResult ValueType::matchParameter(const ValueType *call, const Variable *callVar, const Variable *funcVar)
{ {
ValueType::MatchResult res = ValueType::matchParameter(call, funcVar->valueType()); ValueType vt;
const ValueType* pvt = funcVar->valueType();
if (pvt && funcVar->isArray()) {
vt = *pvt;
++vt.pointer;
pvt = &vt;
}
ValueType::MatchResult res = ValueType::matchParameter(call, pvt);
if (callVar && ((res == ValueType::MatchResult::SAME && call->container) || res == ValueType::MatchResult::UNKNOWN)) { if (callVar && ((res == ValueType::MatchResult::SAME && call->container) || res == ValueType::MatchResult::UNKNOWN)) {
const std::string type1 = getTypeString(callVar->typeStartToken()); const std::string type1 = getTypeString(callVar->typeStartToken());
const std::string type2 = getTypeString(funcVar->typeStartToken()); const std::string type2 = getTypeString(funcVar->typeStartToken());

View File

@ -3305,6 +3305,18 @@ private:
" {}\n" " {}\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("struct String {\n" // #10469
" void Append(uint8_t Val);\n"
" String& operator+=(const char s[]);\n"
" String& operator+=(const std::string& Str) {\n"
" return operator+=(Str.c_str());\n"
" }\n"
" void operator+=(uint8_t Val) {\n"
" Append(Val);\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
} }
void danglingLifetimeBorrowedMembers() void danglingLifetimeBorrowedMembers()