@@ -3456,21 +3456,35 @@ bool Tokenizer::simplifyUsing()
34563456 nameEnd = nameEnd->tokAt (2 );
34573457 if (Token::simpleMatch (nameEnd->next (), " (" ))
34583458 nameEnd = nameEnd->linkAt (1 );
3459+ else {
3460+ while (Token::simpleMatch (nameEnd->next (), " [" ))
3461+ nameEnd = nameEnd->linkAt (1 );
3462+ }
34593463 if (!nameEnd->next ())
34603464 syntaxError (nameEnd);
34613465 TokenList::copyTokens (tok1, start, usingEnd->previous ());
34623466 tok1->deleteThis ();
3463- // the name goes into the innermost parenthesized declarator
3464- Token* decl = tok1->tokAt (tokDistance (start, fpQual));
3467+ // a parenthesis starting with a ptr-operator is a nested declarator, otherwise it is a parameter list
3468+ const auto isNestedDeclarator = [](const Token* paren) {
3469+ if (!Token::simpleMatch (paren, " (" ))
3470+ return false ;
3471+ const Token* t = paren->next ();
3472+ if (Token::simpleMatch (t, " ::" ))
3473+ t = t->next ();
3474+ while (Token::Match (t, " %name% ::" ))
3475+ t = t->tokAt (2 );
3476+ return Token::Match (t, " *|&|&&" );
3477+ };
3478+ // the name goes after the ptr-operators of the innermost nested declarator
3479+ Token* pos = tok1->tokAt (tokDistance (start, fpQual))->next ();
34653480 for (;;) {
3466- Token* inner = decl->next ();
3467- while (inner != decl->link () && inner->str () != " (" )
3468- inner = inner->next ();
3469- if (inner == decl->link ())
3481+ while (Token::Match (pos, " %name%|::|*|&|&&" ))
3482+ pos = pos->next ();
3483+ if (!isNestedDeclarator (pos))
34703484 break ;
3471- decl = inner ;
3485+ pos = pos-> next () ;
34723486 }
3473- Token::move (nameStart, nameEnd, decl-> link () ->previous ());
3487+ Token::move (nameStart, nameEnd, pos ->previous ());
34743488 substitute = true ;
34753489 } else if (fpArgList && fpQual && Token::Match (tok1->next (), " %name%" )) {
34763490 // function pointer
0 commit comments