Skip to content

Commit 491721a

Browse files
Fix spurious variable declaration with unknown macro (danmar#4694)
1 parent 8cc3e0b commit 491721a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6406,6 +6406,8 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
64066406
varName = varName->next();
64076407
else
64086408
--typelen;
6409+
if (isCPP() && Token::Match(varName, "public:|private:|protected:"))
6410+
continue;
64096411
//skip all the pointer part
64106412
bool isPointerOrRef = false;
64116413
while (Token::simpleMatch(varName, "*") || Token::Match(varName, "& %name% ,")) {

test/testvarid.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class TestVarID : public TestFixture {
136136
TEST_CASE(varid_in_class21); // #7788
137137
TEST_CASE(varid_in_class22); // #10872
138138
TEST_CASE(varid_in_class23); // #11293
139+
TEST_CASE(varid_in_class24);
139140
TEST_CASE(varid_namespace_1); // #7272
140141
TEST_CASE(varid_namespace_2); // #7000
141142
TEST_CASE(varid_namespace_3); // #8627
@@ -1988,6 +1989,22 @@ class TestVarID : public TestFixture {
19881989
ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
19891990
}
19901991

1992+
void varid_in_class24() {
1993+
const char code[] = "class A {\n"
1994+
" Q_OBJECT\n"
1995+
"public:\n"
1996+
" using QPtr = QPointer<A>;\n"
1997+
"};\n";
1998+
1999+
const char expected[] = "1: class A {\n"
2000+
"2: Q_OBJECT\n"
2001+
"3: public:\n"
2002+
"4:\n"
2003+
"5: } ;\n";
2004+
2005+
ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
2006+
}
2007+
19912008
void varid_namespace_1() { // #7272
19922009
const char code[] = "namespace Blah {\n"
19932010
" struct foo { int x;};\n"

0 commit comments

Comments
 (0)