File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1838,6 +1838,17 @@ static bool isCastToInteger(const Token* tok)
18381838 return tok && tok->isCast () && tok->valueType () && tok->valueType ()->isIntegral () && tok->valueType ()->pointer == 0 ;
18391839}
18401840
1841+ static const Function* getEnclosingFunction (const Variable* var)
1842+ {
1843+ if (var->isArgument ())
1844+ return var->scope ()->function ;
1845+ const Scope* scope = var->scope ();
1846+ while (scope && scope->type != ScopeType::eFunction) {
1847+ scope = scope->nestedIn ;
1848+ }
1849+ return scope ? scope->function : nullptr ;
1850+ }
1851+
18411852void CheckOther::checkConstPointer ()
18421853{
18431854 if (!mSettings ->severity .isEnabled (Severity::style) &&
@@ -1917,7 +1928,7 @@ void CheckOther::checkConstPointer()
19171928 continue ;
19181929 int argn = -1 ;
19191930 if (Token::simpleMatch (gparent, " return" )) {
1920- const Function* function = gparent-> scope ()-> function ;
1931+ const Function* function = getEnclosingFunction (var) ;
19211932 if (function && (!Function::returnsReference (function) || Function::returnsConst (function)))
19221933 continue ;
19231934 }
You can’t perform that action at this time.
0 commit comments