Fix varid assigned to function (#4991) (#5013)

This commit is contained in:
chrchr-github 2023-04-28 08:27:07 +02:00 committed by GitHub
parent 9c184462ad
commit 5b4c95f229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -4597,7 +4597,8 @@ void Tokenizer::setVarIdPass1()
continue;
if (tok3->isLiteral() ||
(tok3->isName() && (variableMap.hasVariable(tok3->str()) || (tok3->strAt(-1) == "(" && Token::simpleMatch(tok3->next(), "(")))) ||
(tok3->isName() && (variableMap.hasVariable(tok3->str()) ||
(tok3->strAt(-1) == "(" && Token::simpleMatch(tok3->next(), "(") && !Token::simpleMatch(tok3->linkAt(1)->next(), "(")))) ||
tok3->isOp() ||
tok3->str() == "(" ||
notstart.find(tok3->str()) != notstart.end()) {

View File

@ -1197,11 +1197,22 @@ private:
}
void varid66() {
const char code[] = "std::string g();\n"
"const std::string s(g() + \"abc\");\n";
const char expected[] = "1: std :: string g ( ) ;\n"
"2: const std :: string s@1 ( g ( ) + \"abc\" ) ;\n";
ASSERT_EQUALS(expected, tokenize(code));
{
const char code[] = "std::string g();\n"
"const std::string s(g() + \"abc\");\n";
const char expected[] = "1: std :: string g ( ) ;\n"
"2: const std :: string s@1 ( g ( ) + \"abc\" ) ;\n";
ASSERT_EQUALS(expected, tokenize(code));
}
{
const char code[] = "enum E {};\n"
"typedef E(*fp_t)();\n"
"E f(fp_t fp);\n";
const char expected[] = "1: enum E { } ;\n"
"2:\n"
"3: E f ( E ( * fp@1 ) ( ) ) ;\n";
ASSERT_EQUALS(expected, tokenize(code));
}
}
void varid_for_1() {