@@ -1100,6 +1100,29 @@ static bool scopeHasNonTemplateFunction(const Scope* scope, const std::string& n
11001100 });
11011101}
11021102
1103+ // Does this executable scope declare a (non template) function with this name? Such a
1104+ // declaration hides the function templates of the enclosing scopes. The symbol database
1105+ // records only "extern" prototypes declared in a block scope, so the tokens of the scope
1106+ // are scanned for the other prototypes - nested blocks are separate scopes.
1107+ static bool executableScopeDeclaresFunction (const Scope* scope, const std::string& name)
1108+ {
1109+ if (scopeHasNonTemplateFunction (scope, name))
1110+ return true ;
1111+ for (const Token* tok = scope->bodyStart ->next (); tok && tok != scope->bodyEnd ; tok = tok->next ()) {
1112+ if (tok->str () == " {" ) {
1113+ tok = tok->link ();
1114+ continue ;
1115+ }
1116+ if (tok->str () != name || !Token::Match (tok, " %name% (" ) || !Token::simpleMatch (tok->linkAt (1 ), " ) ;" ))
1117+ continue ;
1118+ // "int f ( long ) ;" is a declaration, "return f ( i ) ;" is a call
1119+ const Token* prev = tok->previous ();
1120+ if (Token::Match (prev, " %type%|*|&|::" ) && !prev->isKeyword ())
1121+ return true ;
1122+ }
1123+ return false ;
1124+ }
1125+
11031126namespace {
11041127// The scopes where a call name is looked up, in lookup order: the innermost scope
11051128// with matching declarations wins. At class scopes the transitive base classes are
@@ -1402,6 +1425,9 @@ std::string TemplateSimplifier::deduceFunctionTemplateArguments(
14021425 } else {
14031426 // use the symbol database scopes
14041427 for (const Scope* scope = tok->scope (); scope; scope = scope->nestedIn ) {
1428+ // a function declared in an enclosing block scope hides the templates of the outer scopes
1429+ if (scope->isExecutable () && executableScopeDeclaresFunction (scope, tok->str ()))
1430+ return " " ;
14051431 if (scope->functionOf && scope->functionOf ->isClassOrStructOrUnion ()) {
14061432 // out of class member function body: the class, its base classes and
14071433 // its enclosing scopes come before the lexically enclosing scopes
0 commit comments