Skip to content

Commit 8087cfe

Browse files
committed
Fixed #8627 (Tokenizer::setVarIdPass2: constructor parameter)
1 parent f0826ed commit 8087cfe

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3093,8 +3093,13 @@ void Tokenizer::setVarIdPass2()
30933093
if (tok2->strAt(-1) == ")" || tok2->strAt(-2) == ")")
30943094
setVarIdClassFunction(scopeName2 + classname, tok2, tok2->link(), thisClassVars, structMembers, &mVarId);
30953095
tok2 = tok2->link();
3096-
} else if (tok2->str() == "(" && tok2->link()->strAt(1) != "(")
3096+
} else if (tok2->str() == "(" && tok2->link()->strAt(1) != "(") {
30973097
tok2 = tok2->link();
3098+
3099+
// Skip initialization list
3100+
while (Token::Match(tok2, ") [:,] %name% ("))
3101+
tok2 = tok2->linkAt(3);
3102+
}
30983103
}
30993104

31003105
// Found a member variable..

test/testvarid.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class TestVarID : public TestFixture {
129129
TEST_CASE(varid_in_class21); // #7788
130130
TEST_CASE(varid_namespace_1); // #7272
131131
TEST_CASE(varid_namespace_2); // #7000
132+
TEST_CASE(varid_namespace_3); // #8627
132133
TEST_CASE(varid_initList);
133134
TEST_CASE(varid_initListWithBaseTemplate);
134135
TEST_CASE(varid_initListWithScope);
@@ -1825,6 +1826,41 @@ class TestVarID : public TestFixture {
18251826
ASSERT(actual.find("X@2 = 0") != std::string::npos);
18261827
}
18271828

1829+
std::string getLine(const std::string &code, int lineNumber) {
1830+
std::string nr = MathLib::toString(lineNumber);
1831+
const std::string::size_type pos1 = code.find('\n' + nr + ": ");
1832+
if (pos1 == std::string::npos)
1833+
return "";
1834+
const std::string::size_type pos2 = code.find('\n', pos1+1);
1835+
if (pos2 == std::string::npos)
1836+
return "";
1837+
return code.substr(pos1+1, pos2-pos1-1);
1838+
}
1839+
1840+
void varid_namespace_3() { // #8627
1841+
const char code[] = "namespace foo {\n"
1842+
"struct Bar {\n"
1843+
" explicit Bar(int type);\n"
1844+
" void f();\n"
1845+
" int type;\n" // <- Same varid here ...
1846+
"};\n"
1847+
"\n"
1848+
"Bar::Bar(int type) : type(type) {}\n"
1849+
"\n"
1850+
"void Bar::f() {\n"
1851+
" type = 0;\n" // <- ... and here
1852+
"}\n"
1853+
"}";
1854+
1855+
const std::string actual = tokenize(code, false, "test.cpp");
1856+
1857+
const std::string line5 = getLine(actual, 5);
1858+
const std::string line11 = getLine(actual, 11);
1859+
1860+
ASSERT_EQUALS("5: int type@2 ;", getLine(actual,5));
1861+
ASSERT_EQUALS("11: type@2 = 0 ;", getLine(actual,11));
1862+
}
1863+
18281864
void varid_initList() {
18291865
const char code1[] = "class A {\n"
18301866
" A() : x(0) {}\n"

0 commit comments

Comments
 (0)