Skip to content

Commit 5b4c95f

Browse files
Fix varid assigned to function (#4991) (#5013)
1 parent 9c18446 commit 5b4c95f

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4597,7 +4597,8 @@ void Tokenizer::setVarIdPass1()
45974597
continue;
45984598

45994599
if (tok3->isLiteral() ||
4600-
(tok3->isName() && (variableMap.hasVariable(tok3->str()) || (tok3->strAt(-1) == "(" && Token::simpleMatch(tok3->next(), "(")))) ||
4600+
(tok3->isName() && (variableMap.hasVariable(tok3->str()) ||
4601+
(tok3->strAt(-1) == "(" && Token::simpleMatch(tok3->next(), "(") && !Token::simpleMatch(tok3->linkAt(1)->next(), "(")))) ||
46014602
tok3->isOp() ||
46024603
tok3->str() == "(" ||
46034604
notstart.find(tok3->str()) != notstart.end()) {

test/testvarid.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,11 +1197,22 @@ class TestVarID : public TestFixture {
11971197
}
11981198

11991199
void varid66() {
1200-
const char code[] = "std::string g();\n"
1201-
"const std::string s(g() + \"abc\");\n";
1202-
const char expected[] = "1: std :: string g ( ) ;\n"
1203-
"2: const std :: string s@1 ( g ( ) + \"abc\" ) ;\n";
1204-
ASSERT_EQUALS(expected, tokenize(code));
1200+
{
1201+
const char code[] = "std::string g();\n"
1202+
"const std::string s(g() + \"abc\");\n";
1203+
const char expected[] = "1: std :: string g ( ) ;\n"
1204+
"2: const std :: string s@1 ( g ( ) + \"abc\" ) ;\n";
1205+
ASSERT_EQUALS(expected, tokenize(code));
1206+
}
1207+
{
1208+
const char code[] = "enum E {};\n"
1209+
"typedef E(*fp_t)();\n"
1210+
"E f(fp_t fp);\n";
1211+
const char expected[] = "1: enum E { } ;\n"
1212+
"2:\n"
1213+
"3: E f ( E ( * fp@1 ) ( ) ) ;\n";
1214+
ASSERT_EQUALS(expected, tokenize(code));
1215+
}
12051216
}
12061217

12071218
void varid_for_1() {

0 commit comments

Comments
 (0)