Fix #11052 inline static global struct declaration interferes with checks (#4098)

This commit is contained in:
chrchr-github 2022-05-10 20:43:11 +02:00 committed by GitHub
parent 759c16fcef
commit a70d11adb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View File

@ -4560,7 +4560,7 @@ static const Token* skipPointers(const Token* tok)
static const Token* skipPointersAndQualifiers(const Token* tok)
{
tok = skipPointers(tok);
while (Token::Match(tok, "const|volatile")) {
while (Token::Match(tok, "const|static|volatile")) {
tok = tok->next();
tok = skipPointers(tok);
}

View File

@ -10825,7 +10825,7 @@ void Tokenizer::simplifyStructDecl()
Token *restart = next;
// check for named type
if (Token::Match(tok->next(), "const| *|&| const| (| %type% )| ,|;|[|=|(|{")) {
if (Token::Match(tok->next(), "const|static|volatile| *|&| const| (| %type% )| ,|;|[|=|(|{")) {
tok->insertToken(";");
tok = tok->next();
while (!Token::Match(start, "struct|class|union|enum")) {

View File

@ -2769,6 +2769,10 @@ private:
" a[i] = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str());
check("struct S { int b; } static e[1];\n" // #11052
"int f() { return e[1].b; }\n");
ASSERT_EQUALS("[test.cpp:2]: (error) Array 'e[1]' accessed at index 1, which is out of bounds.\n", errout.str());
}

View File

@ -1960,6 +1960,11 @@ private:
const char code2[] = "enum A {} (a);";
const char expected2[] = "enum A { } ; enum A a ;";
ASSERT_EQUALS(expected2, tokenizeAndStringify(code2));
// #11052
const char code3[] = "struct a { int b; } static e[1];";
const char expected3[] = "struct a { int b ; } ; struct a static e [ 1 ] ;";
ASSERT_EQUALS(expected3, tokenizeAndStringify(code3));
}
void vardecl1() {