From e4bea02cad207dcb21c0162ba7074fdfbefecb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 15 Apr 2020 20:56:21 +0200 Subject: [PATCH] Fixed #7578 (varid not set for 'pointer to array' member variable in method) --- lib/tokenize.cpp | 2 +- test/testvarid.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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"