From be1486609539887c69109f5c48d1928818dab1a4 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 1 Nov 2021 13:21:03 -0500 Subject: [PATCH] Run valueFlowSubfunction in reverse order of functions (#3540) --- lib/valueflow.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index c391b842c..104abb492 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6261,10 +6261,31 @@ static void valueFlowLibraryFunction(Token *tok, const std::string &returnValue, }); } +template +struct IteratorRange +{ + Iterator mBegin; + Iterator mEnd; + + Iterator begin() const { + return mBegin; + } + + Iterator end() const { + return mEnd; + } +}; + +template +IteratorRange MakeIteratorRange(Iterator start, Iterator last) +{ + return {start, last}; +} + static void valueFlowSubFunction(TokenList* tokenlist, SymbolDatabase* symboldatabase, ErrorLogger* errorLogger, const Settings* settings) { int id = 0; - for (const Scope* scope : symboldatabase->functionScopes) { + for (const Scope* scope : MakeIteratorRange(symboldatabase->functionScopes.rbegin(), symboldatabase->functionScopes.rend())) { const Function* function = scope->function; if (!function) continue;