Fixx issue 9355: FP constParameter when returning non-const reference to struct member (#2373)

This commit is contained in:
Paul Fultz II 2019-11-17 23:39:50 -06:00 committed by Daniel Marjamäki
parent 7f6ebaa6b2
commit ed1acc319d
2 changed files with 9 additions and 1 deletions

View File

@ -1357,7 +1357,7 @@ void CheckOther::checkConstVariable()
if (isVariableChanged(var, mSettings, mTokenizer->isCPP()))
continue;
if (Function::returnsReference(function) &&
Token::findmatch(var->nameToken(), "return %varid% ;|[", scope->bodyEnd, var->declarationId()))
Token::findmatch(var->nameToken(), "return %varid% ;|[|.", scope->bodyEnd, var->declarationId()))
continue;
// Skip if address is taken
if (Token::findmatch(var->nameToken(), "& %varid%", scope->bodyEnd, var->declarationId()))

View File

@ -1946,6 +1946,14 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("struct S {\n"
" int i;\n"
"};\n"
"int& f(S& s) {\n"
" return s.i;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void e();\n"
"void g(void);\n"
"void h(void);\n"