Merge pull request #2698 from pfultz2/const-param-casts
Fix issue 9778: False positive: constParameter when returning non-const reference cast
This commit is contained in:
commit
72bdeb9307
|
@ -1370,6 +1370,8 @@ void CheckOther::checkConstVariable()
|
||||||
if (std::any_of(returns.begin(), returns.end(), [&](const Token* retTok) {
|
if (std::any_of(returns.begin(), returns.end(), [&](const Token* retTok) {
|
||||||
if (retTok->varId() == var->declarationId())
|
if (retTok->varId() == var->declarationId())
|
||||||
return true;
|
return true;
|
||||||
|
while (retTok && retTok->isCast())
|
||||||
|
retTok = retTok->astOperand2();
|
||||||
while (Token::simpleMatch(retTok, "."))
|
while (Token::simpleMatch(retTok, "."))
|
||||||
retTok = retTok->astOperand2();
|
retTok = retTok->astOperand2();
|
||||||
const Variable* retVar = getLifetimeVariable(getParentLifetime(retTok));
|
const Variable* retVar = getLifetimeVariable(getParentLifetime(retTok));
|
||||||
|
|
|
@ -2040,6 +2040,14 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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"
|
check("void e();\n"
|
||||||
"void g(void);\n"
|
"void g(void);\n"
|
||||||
"void h(void);\n"
|
"void h(void);\n"
|
||||||
|
|
Loading…
Reference in New Issue