@@ -1366,7 +1366,7 @@ void CheckOther::checkPassByReference()
13661366
13671367 const bool isConst = var->isConst ();
13681368 if (isConst) {
1369- passedByValueError (var-> nameToken (), var-> name () , inconclusive);
1369+ passedByValueError (var, inconclusive);
13701370 continue ;
13711371 }
13721372
@@ -1375,18 +1375,26 @@ void CheckOther::checkPassByReference()
13751375 continue ;
13761376
13771377 if (canBeConst (var, mSettings )) {
1378- passedByValueError (var-> nameToken (), var-> name () , inconclusive);
1378+ passedByValueError (var, inconclusive);
13791379 }
13801380 }
13811381}
13821382
1383- void CheckOther::passedByValueError (const Token *tok, const std::string &parname , bool inconclusive)
1383+ void CheckOther::passedByValueError (const Variable* var , bool inconclusive)
13841384{
1385- reportError (tok, Severity::performance, " passedByValue" ,
1386- " $symbol:" + parname + " \n "
1387- " Function parameter '$symbol' should be passed by const reference.\n "
1388- " Parameter '$symbol' is passed by value. It could be passed "
1389- " as a const reference which is usually faster and recommended in C++." , CWE398, inconclusive ? Certainty::inconclusive : Certainty::normal);
1385+ std::string id = " passedByValue" ;
1386+ std::string msg = " $symbol:" + (var ? var->name () : " " ) + " \n "
1387+ " Function parameter '$symbol' should be passed by const reference." ;
1388+ ErrorPath errorPath;
1389+ if (var && var->scope () && var->scope ()->function && var->scope ()->function ->functionPointerUsage ) {
1390+ id += " Callback" ;
1391+ errorPath.emplace_front (var->scope ()->function ->functionPointerUsage , " Function pointer used here." );
1392+ msg += " However it seems that '" + var->scope ()->function ->name () + " ' is a callback function." ;
1393+ }
1394+ if (var)
1395+ errorPath.emplace_back (var->nameToken (), msg);
1396+ msg += " \n Parameter '$symbol' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++." ;
1397+ reportError (errorPath, Severity::performance, id.c_str (), msg, CWE398, inconclusive ? Certainty::inconclusive : Certainty::normal);
13901398}
13911399
13921400static bool isUnusedVariable (const Variable *var)
0 commit comments