Skip to content

Commit

Permalink
Fix #13291 Wrong varid for member pointer to pointer (#6988)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 9, 2024
1 parent 7c6fdb2 commit 7263860
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4297,7 +4297,7 @@ static bool setVarIdParseDeclaration(Token*& tok, const VariableMap& variableMap
return false;
}
bracket = true; // Skip: Seems to be valid pointer to array or function pointer
} else if (singleNameCount >= 1 && Token::Match(tok2, "( * %name% [") && Token::Match(tok2->linkAt(3), "] ) [;,]")) {
} else if (singleNameCount >= 1 && Token::Match(tok2, "( * %name% [") && Token::Match(tok2->linkAt(3), "] ) [;,]") && !variableMap.map(false).count(tok2->strAt(2))) {
bracket = true;
} else if (singleNameCount >= 1 && tok2->previous() && tok2->previous()->isStandardType() && Token::Match(tok2, "( *|&| %name% ) ;")) {
bracket = true;
Expand Down
15 changes: 14 additions & 1 deletion test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class TestVarID : public TestFixture {
TEST_CASE(varid61); // #4988 inline function
TEST_CASE(varid62);
TEST_CASE(varid63);
TEST_CASE(varid64); // #9928 - extern const char (*x[256])
TEST_CASE(varid64); // #9922 - extern const char (*x[256])
TEST_CASE(varid65); // #10936
TEST_CASE(varid66);
TEST_CASE(varid67); // #11711 - NOT function pointer
Expand Down Expand Up @@ -147,6 +147,7 @@ class TestVarID : public TestFixture {
TEST_CASE(varid_in_class24);
TEST_CASE(varid_in_class25);
TEST_CASE(varid_in_class26);
TEST_CASE(varid_in_class27);
TEST_CASE(varid_namespace_1); // #7272
TEST_CASE(varid_namespace_2); // #7000
TEST_CASE(varid_namespace_3); // #8627
Expand Down Expand Up @@ -2285,6 +2286,18 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(expected, tokenize(code, true));
}

void varid_in_class27() {
const char code[] = "struct S {\n" // #13291
" int** pp;\n"
" void f() { int x(*pp[0]); }\n"
"};\n";
const char expected[] = "1: struct S {\n"
"2: int * * pp@1 ;\n"
"3: void f ( ) { int x@2 ( * pp@1 [ 0 ] ) ; }\n"
"4: } ;\n";
ASSERT_EQUALS(expected, tokenize(code, true));
}

void varid_namespace_1() { // #7272
const char code[] = "namespace Blah {\n"
" struct foo { int x;};\n"
Expand Down

0 comments on commit 7263860

Please sign in to comment.