diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c1380c29d..5f7ad136b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3803,7 +3803,7 @@ void Tokenizer::setVarIdPass2() if (tok2->strAt(-1) == ")" || tok2->strAt(-2) == ")") setVarIdClassFunction(scopeName2 + classname, tok2, tok2->link(), thisClassVars, structMembers, &mVarId); tok2 = tok2->link(); - } else if (tok2->str() == "(" && tok2->link()->strAt(1) != "(") { + } else if (Token::Match(tok2, "( %name%|)") && !Token::Match(tok2->link(), "(|[")) { tok2 = tok2->link(); // Skip initialization list diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 08dbc4c15..538d211b8 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -187,6 +187,7 @@ private: TEST_CASE(varidclass17); // #6073 TEST_CASE(varidclass18); TEST_CASE(varidclass19); // initializer list + TEST_CASE(varidclass20); // #7578: int (*p)[2] TEST_CASE(varid_classnameshaddowsvariablename); // #3990 TEST_CASE(varidnamespace1); @@ -2989,6 +2990,20 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } + void varidclass20() { // #7578: int (*p)[2] + const char code[] = "struct S {\n" + " int (*p)[2];\n" + " S();\n" + "};\n" + "S::S() { p[0] = 0; }"; + const char expected[] = "1: struct S {\n" + "2: int ( * p@1 ) [ 2 ] ;\n" + "3: S ( ) ;\n" + "4: } ;\n" + "5: S :: S ( ) { p@1 [ 0 ] = 0 ; }\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + void varid_classnameshaddowsvariablename() { const char code[] = "class Data;\n" "void strange_declarated(const Data& Data);\n"