Fix spurious variable declaration with unknown macro (#4694)

This commit is contained in:
chrchr-github 2023-01-09 16:11:26 +01:00 committed by GitHub
parent 8cc3e0b2ff
commit 491721a6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -6406,6 +6406,8 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
varName = varName->next();
else
--typelen;
if (isCPP() && Token::Match(varName, "public:|private:|protected:"))
continue;
//skip all the pointer part
bool isPointerOrRef = false;
while (Token::simpleMatch(varName, "*") || Token::Match(varName, "& %name% ,")) {

View File

@ -136,6 +136,7 @@ private:
TEST_CASE(varid_in_class21); // #7788
TEST_CASE(varid_in_class22); // #10872
TEST_CASE(varid_in_class23); // #11293
TEST_CASE(varid_in_class24);
TEST_CASE(varid_namespace_1); // #7272
TEST_CASE(varid_namespace_2); // #7000
TEST_CASE(varid_namespace_3); // #8627
@ -1988,6 +1989,22 @@ private:
ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
}
void varid_in_class24() {
const char code[] = "class A {\n"
" Q_OBJECT\n"
"public:\n"
" using QPtr = QPointer<A>;\n"
"};\n";
const char expected[] = "1: class A {\n"
"2: Q_OBJECT\n"
"3: public:\n"
"4:\n"
"5: } ;\n";
ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
}
void varid_namespace_1() { // #7272
const char code[] = "namespace Blah {\n"
" struct foo { int x;};\n"