@@ -3295,15 +3295,36 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
32953295 const Token* ftok = getTokenArgumentFunction (tok, argnr);
32963296 if (!ftok)
32973297 return ExprUsage::None;
3298- if (ftok->function ()) {
3298+ const Function* func = ftok->function ();
3299+ // variable init/constructor call?
3300+ if (!func && ftok->variable () && ftok == ftok->variable ()->nameToken ()) {
3301+ // STL types or containers don't initialize external variables
3302+ if (ftok->variable ()->isStlType () || (ftok->variable ()->valueType () && ftok->variable ()->valueType ()->container ))
3303+ return ExprUsage::Used;
3304+ // TODO: resolve multiple constructors
3305+ if (ftok->variable ()->type () && ftok->variable ()->type ()->classScope ) {
3306+ const int nCtor = ftok->variable ()->type ()->classScope ->numConstructors ;
3307+ if (nCtor == 0 )
3308+ return ExprUsage::Used;
3309+ if (nCtor == 1 ) {
3310+ const Scope* scope = ftok->variable ()->type ()->classScope ;
3311+ auto it = std::find_if (scope->functionList .begin (), scope->functionList .end (), [](const Function& f) {
3312+ return f.isConstructor ();
3313+ });
3314+ if (it != scope->functionList .end ())
3315+ func = &*it;
3316+ }
3317+ }
3318+ }
3319+ if (func) {
32993320 std::vector<const Variable*> args = getArgumentVars (ftok, argnr);
33003321 for (const Variable* arg : args) {
33013322 if (!arg)
33023323 continue ;
33033324 if (arg->isReference () || (arg->isPointer () && indirect == 1 )) {
3304- if (!ftok-> function () ->hasBody ())
3325+ if (!func ->hasBody ())
33053326 return ExprUsage::PassedByReference;
3306- for (const Token* bodytok = ftok-> function ()-> functionScope ->bodyStart ; bodytok != ftok-> function () ->functionScope ->bodyEnd ; bodytok = bodytok->next ()) {
3327+ for (const Token* bodytok = func-> functionScope ->bodyStart ; bodytok != func ->functionScope ->bodyEnd ; bodytok = bodytok->next ()) {
33073328 if (bodytok->variable () == arg) {
33083329 if (arg->isReference ())
33093330 return ExprUsage::PassedByReference;
@@ -3321,11 +3342,6 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
33213342 return ExprUsage::Used;
33223343 } else if (ftok->str () == " {" ) {
33233344 return indirect == 0 ? ExprUsage::Used : ExprUsage::Inconclusive;
3324- } else if (ftok->variable () && ftok == ftok->variable ()->nameToken ()) { // variable init/constructor call
3325- if (ftok->variable ()->type () && ftok->variable ()->type ()->classScope && ftok->variable ()->type ()->classScope ->numConstructors == 0 )
3326- return ExprUsage::Used;
3327- if (ftok->variable ()->isStlType () || (ftok->variable ()->valueType () && ftok->variable ()->valueType ()->container )) // STL types or containers don't initialize external variables
3328- return ExprUsage::Used;
33293345 } else {
33303346 const bool isnullbad = settings.library .isnullargbad (ftok, argnr + 1 );
33313347 if (indirect == 0 && astIsPointer (tok) && !addressOf && isnullbad)
0 commit comments