@@ -214,7 +214,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
214214 funcname = tok->next ();
215215 while (Token::Match (funcname, " %name% :: %name%" ))
216216 funcname = funcname->tokAt (2 );
217- } else if (Token::Match (tok, " [;{}.,()[=+-/|!?:]" )) {
217+ } else if (tok-> scope ()-> type != Scope::ScopeType::eEnum && Token::Match (tok, " [;{}.,()[=+-/|!?:]" )) {
218218 funcname = tok->next ();
219219 if (funcname && funcname->str () == " &" )
220220 funcname = funcname->next ();
@@ -305,23 +305,23 @@ static bool isOperatorFunction(const std::string & funcName)
305305
306306bool CheckUnusedFunctions::check (ErrorLogger * const errorLogger, const Settings& settings) const
307307{
308- bool errors = false ;
308+ using ErrorParams = std::tuple<std::string, unsigned int , std::string>;
309+ std::vector<ErrorParams> errors; // ensure well-defined order
310+
309311 for (std::unordered_map<std::string, FunctionUsage>::const_iterator it = mFunctions .cbegin (); it != mFunctions .cend (); ++it) {
310312 const FunctionUsage &func = it->second ;
311313 if (func.usedOtherFile || func.filename .empty ())
312314 continue ;
313315 if (it->first == " main" ||
314- (settings.isWindowsPlatform () && (it->first == " WinMain" || it->first == " _tmain" )) ||
315- it->first == " if" )
316+ (settings.isWindowsPlatform () && (it->first == " WinMain" || it->first == " _tmain" )))
316317 continue ;
317318 if (!func.usedSameFile ) {
318319 if (isOperatorFunction (it->first ))
319320 continue ;
320321 std::string filename;
321322 if (func.filename != " +" )
322323 filename = func.filename ;
323- unusedFunctionError (errorLogger, filename, func.lineNumber , it->first );
324- errors = true ;
324+ errors.emplace_back (filename, func.lineNumber , it->first );
325325 } else if (!func.usedOtherFile ) {
326326 /* * @todo add error message "function is only used in <file> it can be static" */
327327 /*
@@ -332,7 +332,10 @@ bool CheckUnusedFunctions::check(ErrorLogger * const errorLogger, const Settings
332332 */
333333 }
334334 }
335- return errors;
335+ std::sort (errors.begin (), errors.end ());
336+ for (const auto & e : errors)
337+ unusedFunctionError (errorLogger, std::get<0 >(e), std::get<1 >(e), std::get<2 >(e));
338+ return !errors.empty ();
336339}
337340
338341void CheckUnusedFunctions::unusedFunctionError (ErrorLogger * const errorLogger,
0 commit comments