varid: set varid for 'extern const char (*x[256]);'. This is a partial fix for #9922

This commit is contained in:
Daniel Marjamäki 2020-09-29 10:53:20 +02:00
parent d901edd4af
commit ad9b2741cd
2 changed files with 9 additions and 0 deletions

View File

@ -3070,6 +3070,8 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map<std::stri
ref = !bracket;
} else if (singleNameCount >= 1 && Token::Match(tok2, "( [*&]") && Token::Match(tok2->link()->next(), "(|[")) {
bracket = true; // Skip: Seems to be valid pointer to array or function pointer
} else if (singleNameCount >= 1 && Token::Match(tok2, "( * %name% [") && Token::Match(tok2->linkAt(3), "] ) [;,]")) {
bracket = true;
} else if (tok2->str() == "::") {
singleNameCount = 0;
} else if (tok2->str() != "*" && tok2->str() != "::" && tok2->str() != "...") {

View File

@ -94,6 +94,7 @@ private:
TEST_CASE(varid61); // #4988 inline function
TEST_CASE(varid62);
TEST_CASE(varid63);
TEST_CASE(varid64); // #9928 - extern const char (*x[256])
TEST_CASE(varid_for_1);
TEST_CASE(varid_for_2);
TEST_CASE(varid_cpp_keywords_in_c_code);
@ -1147,6 +1148,12 @@ private:
ASSERT_EQUALS(expected, tokenize(code));
}
void varid64() {
const char code[] = "extern const char (*x[256]);";
const char expected[] = "1: extern const char ( * x@1 [ 256 ] ) ;\n";
ASSERT_EQUALS(expected, tokenize(code));
}
void varid_for_1() {
const char code[] = "void foo(int a, int b) {\n"
" for (int a=1,b=2;;) {}\n"