Fix #12120 FP constStatement with class in C code (#5594)

This commit is contained in:
chrchr-github 2023-10-25 10:05:42 +02:00 committed by GitHub
parent 122e142726
commit 502d7ea6db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -5616,13 +5616,6 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
// If typedef handling is refactored and moved to symboldatabase someday we can remove this // If typedef handling is refactored and moved to symboldatabase someday we can remove this
prepareTernaryOpForAST(); prepareTernaryOpForAST();
for (Token* tok = list.front(); tok;) {
if (Token::Match(tok, "union|struct|class union|struct|class"))
tok->deleteNext();
else
tok = tok->next();
}
// class x y { // class x y {
if (isCPP() && mSettings->severity.isEnabled(Severity::information)) { if (isCPP() && mSettings->severity.isEnabled(Severity::information)) {
for (const Token *tok = list.front(); tok; tok = tok->next()) { for (const Token *tok = list.front(); tok; tok = tok->next()) {

View File

@ -103,6 +103,7 @@ private:
TEST_CASE(varid_for_2); TEST_CASE(varid_for_2);
TEST_CASE(varid_cpp_keywords_in_c_code); TEST_CASE(varid_cpp_keywords_in_c_code);
TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete" TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete"
TEST_CASE(varid_cpp_keywords_in_c_code3);
TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall2);
TEST_CASE(varidFunctionCall3); TEST_CASE(varidFunctionCall3);
@ -1298,6 +1299,12 @@ private:
tokenize(code, "test.c"); tokenize(code, "test.c");
} }
void varid_cpp_keywords_in_c_code3() { // #12120
const char code[] = "const struct class *p;";
const char expected[] = "1: const struct class * p@1 ;\n";
ASSERT_EQUALS(expected, tokenize(code, "test.c"));
}
void varidFunctionCall1() { void varidFunctionCall1() {
const char code[] ="void f() {\n" const char code[] ="void f() {\n"
" int x;\n" " int x;\n"