@@ -1170,7 +1170,7 @@ static int estimateSize(const Type* type, const Settings* settings, const Symbol
11701170 return cumulatedSize;
11711171}
11721172
1173- static bool canBeConst (const Variable *var)
1173+ static bool canBeConst (const Variable *var, const Settings* settings )
11741174{
11751175 {
11761176 // check initializer list. If variable is moved from it can't be const.
@@ -1214,17 +1214,26 @@ static bool canBeConst(const Variable *var)
12141214 argNr++;
12151215 tok3 = tok3->previous ();
12161216 }
1217- if (!tok3 || tok3->str () != " (" || !tok3-> astOperand1 () || !tok3-> astOperand1 ()-> function () )
1217+ if (!tok3 || tok3->str () != " (" )
12181218 return false ;
1219- else {
1220- const Variable* argVar = tok3->astOperand1 ()->function ()->getArgumentVar (argNr);
1219+ const Token* functionTok = tok3->astOperand1 ();
1220+ if (!functionTok)
1221+ return false ;
1222+ const Function* tokFunction = functionTok->function ();
1223+ if (!tokFunction && functionTok->str () == " ." && (functionTok = functionTok->astOperand2 ()))
1224+ tokFunction = functionTok->function ();
1225+ if (tokFunction) {
1226+ const Variable* argVar = tokFunction->getArgumentVar (argNr);
12211227 if (!argVar || (!argVar->isConst () && argVar->isReference ()))
12221228 return false ;
12231229 }
1230+ else if (!settings->library .isFunctionConst (functionTok))
1231+ return false ;
12241232 } else if (parent->isUnaryOp (" &" )) {
12251233 // TODO: check how pointer is used
12261234 return false ;
1227- } else if (parent->isConstOp ())
1235+ } else if (parent->isConstOp () ||
1236+ (parent->astOperand2 () && settings->library .isFunctionConst (parent->astOperand2 ())))
12281237 continue ;
12291238 else if (parent->isAssignmentOp ()) {
12301239 if (parent->astOperand1 () == tok2)
@@ -1290,7 +1299,7 @@ void CheckOther::checkPassByReference()
12901299 if (!var->scope () || var->scope ()->function ->hasVirtualSpecifier ())
12911300 continue ;
12921301
1293- if (canBeConst (var)) {
1302+ if (canBeConst (var, mSettings )) {
12941303 passedByValueError (var->nameToken (), var->name (), inconclusive);
12951304 }
12961305 }
0 commit comments