diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 504e49b66..442de1c58 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -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); } diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 65888aeed..165b6c4b7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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")) { diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 05b3dffe9..14038828d 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -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()); } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index c875372c5..be3efda9a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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() {