Fix spurious variable declaration with unknown macro and using (#4698)

This commit is contained in:
chrchr-github 2023-01-18 17:11:41 +01:00 committed by GitHub
parent 25a6146ffa
commit 0b62c73ff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 11 deletions

View File

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

View File

@ -1990,18 +1990,28 @@ private:
} }
void varid_in_class24() { void varid_in_class24() {
const char code[] = "class A {\n" const char *code{}, *expected{};
" Q_OBJECT\n"
"public:\n"
" using QPtr = QPointer<A>;\n"
"};\n";
const char expected[] = "1: class A {\n" code = "class A {\n"
"2: Q_OBJECT\n" " Q_OBJECT\n"
"3: public:\n" "public:\n"
"4:\n" " using QPtr = QPointer<A>;\n"
"5: } ;\n"; "};\n";
expected = "1: class A {\n"
"2: Q_OBJECT\n"
"3: public:\n"
"4:\n"
"5: } ;\n";
ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
code = "class A {\n"
" Q_OBJECT\n"
" using QPtr = QPointer<A>;\n"
"};\n";
expected = "1: class A {\n"
"2: Q_OBJECT\n"
"3:\n"
"4: } ;\n";
ASSERT_EQUALS(expected, tokenize(code, "test.cpp")); ASSERT_EQUALS(expected, tokenize(code, "test.cpp"));
} }