Skip to content

Commit 7263860

Browse files
Fix #13291 Wrong varid for member pointer to pointer (#6988)
1 parent 7c6fdb2 commit 7263860

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4297,7 +4297,7 @@ static bool setVarIdParseDeclaration(Token*& tok, const VariableMap& variableMap
42974297
return false;
42984298
}
42994299
bracket = true; // Skip: Seems to be valid pointer to array or function pointer
4300-
} else if (singleNameCount >= 1 && Token::Match(tok2, "( * %name% [") && Token::Match(tok2->linkAt(3), "] ) [;,]")) {
4300+
} else if (singleNameCount >= 1 && Token::Match(tok2, "( * %name% [") && Token::Match(tok2->linkAt(3), "] ) [;,]") && !variableMap.map(false).count(tok2->strAt(2))) {
43014301
bracket = true;
43024302
} else if (singleNameCount >= 1 && tok2->previous() && tok2->previous()->isStandardType() && Token::Match(tok2, "( *|&| %name% ) ;")) {
43034303
bracket = true;

test/testvarid.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class TestVarID : public TestFixture {
9696
TEST_CASE(varid61); // #4988 inline function
9797
TEST_CASE(varid62);
9898
TEST_CASE(varid63);
99-
TEST_CASE(varid64); // #9928 - extern const char (*x[256])
99+
TEST_CASE(varid64); // #9922 - extern const char (*x[256])
100100
TEST_CASE(varid65); // #10936
101101
TEST_CASE(varid66);
102102
TEST_CASE(varid67); // #11711 - NOT function pointer
@@ -147,6 +147,7 @@ class TestVarID : public TestFixture {
147147
TEST_CASE(varid_in_class24);
148148
TEST_CASE(varid_in_class25);
149149
TEST_CASE(varid_in_class26);
150+
TEST_CASE(varid_in_class27);
150151
TEST_CASE(varid_namespace_1); // #7272
151152
TEST_CASE(varid_namespace_2); // #7000
152153
TEST_CASE(varid_namespace_3); // #8627
@@ -2285,6 +2286,18 @@ class TestVarID : public TestFixture {
22852286
ASSERT_EQUALS(expected, tokenize(code, true));
22862287
}
22872288

2289+
void varid_in_class27() {
2290+
const char code[] = "struct S {\n" // #13291
2291+
" int** pp;\n"
2292+
" void f() { int x(*pp[0]); }\n"
2293+
"};\n";
2294+
const char expected[] = "1: struct S {\n"
2295+
"2: int * * pp@1 ;\n"
2296+
"3: void f ( ) { int x@2 ( * pp@1 [ 0 ] ) ; }\n"
2297+
"4: } ;\n";
2298+
ASSERT_EQUALS(expected, tokenize(code, true));
2299+
}
2300+
22882301
void varid_namespace_1() { // #7272
22892302
const char code[] = "namespace Blah {\n"
22902303
" struct foo { int x;};\n"

0 commit comments

Comments
 (0)