From 1b89c998f5b698c40691b02a999485d0d3ff3555 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 12 Jan 2022 22:05:30 +0100 Subject: [PATCH] Fix #10469 FP returnTempReference with overloaded operator+= (#3678) --- lib/symboldatabase.cpp | 9 ++++++++- test/testautovariables.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 7c84024f9..5cdc96d74 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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 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)) { const std::string type1 = getTypeString(callVar->typeStartToken()); const std::string type2 = getTypeString(funcVar->typeStartToken()); diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index a25e935b0..cb8ad157a 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -3305,6 +3305,18 @@ private: " {}\n" "}\n"); 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()