diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 1acf1b1f6c4..40c40f1b8d1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4712,6 +4712,41 @@ void Tokenizer::setVarIdPass1() bool initlist = false; bool inlineFunction = false; for (Token *tok = list.front(); tok; tok = tok->next()) { + if (Token::simpleMatch(tok, ") (") && Token::simpleMatch(tok->link(), "( *")) { + const Token *typeTok = tok->link()->previous(); + while (Token::Match(typeTok, "*|&")) { + typeTok = tok->previous(); + } + + if (!Token::Match(typeTok, "%type%")) + continue; + + // Add globally unique varids to function pointer arguments + variableMap.enterScope(); + + tok = tok->next(); + const Token *endTok = tok->link(); + tok = tok->next(); + + for (Token *argTok = tok; argTok != endTok; argTok = argTok->next()) { + if (Token::simpleMatch(argTok, "(")) + argTok = argTok->link(); + + if (!Token::Match(argTok, "%name%|*|&|&& %name% ,|)")) + continue; + + argTok = argTok->next(); + + if (argTok->isStandardType()) + continue; + + variableMap.addVariable(argTok->str(), false); + argTok->varId(variableMap.getVarId()); + } + + variableMap.leaveScope(); + continue; + } if (tok->isOp()) continue; if (cpp && Token::simpleMatch(tok, "template <")) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 64b7b6664be..2b0e82cfc8e 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -3540,9 +3540,15 @@ class TestVarID : public TestFixture { "}\n"; ASSERT_EQUALS("1: void f ( ) {\n" "2: int * p@1 ;\n" - "3: void ( * a@2 [ 1 ] ) ( int * p ) = { 0 } ;\n" + "3: void ( * a@2 [ 1 ] ) ( int * p@3 ) = { 0 } ;\n" "4: }\n", tokenize(code4)); + + const char code5[] = "int *p;\n" + "void (*a[1])(int* p) = { 0 } ;\n"; + ASSERT_EQUALS("1: int * p@1 ;\n" + "2: void ( * a@2 [ 1 ] ) ( int * p@3 ) = { 0 } ;\n" + , tokenize(code5)); } void varid_alignas() {