Fix issue 9778: False positive: constParameter when returning non-const reference cast
This commit is contained in:
parent
b33326bf51
commit
cf475fab51
|
@ -1368,8 +1368,10 @@ void CheckOther::checkConstVariable()
|
|||
if (Function::returnsReference(function)) {
|
||||
std::vector<const Token*> returns = Function::findReturns(function);
|
||||
if (std::any_of(returns.begin(), returns.end(), [&](const Token* retTok) {
|
||||
if (retTok->varId() == var->declarationId())
|
||||
if (retTok->varId() == var->declarationId())
|
||||
return true;
|
||||
while (retTok && retTok->isCast())
|
||||
retTok = retTok->astOperand2();
|
||||
while (Token::simpleMatch(retTok, "."))
|
||||
retTok = retTok->astOperand2();
|
||||
const Variable* retVar = getLifetimeVariable(getParentLifetime(retTok));
|
||||
|
|
|
@ -2040,6 +2040,14 @@ private:
|
|||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #9778
|
||||
check("struct A {};\n"
|
||||
"struct B : A {};\n"
|
||||
"B& f(A& x) {\n"
|
||||
" return static_cast<B&>(x);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void e();\n"
|
||||
"void g(void);\n"
|
||||
"void h(void);\n"
|
||||
|
|
Loading…
Reference in New Issue