Skip to content

Commit

Permalink
Fix #13666 Missing varid for struct member in return statement (danma…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Feb 27, 2025
1 parent 2444687 commit 1439297
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4351,7 +4351,7 @@ static void setVarIdStructMembers(Token *&tok1,

while (Token::Match(tok->next(), ")| . %name% !!(")) {
// Don't set varid for trailing return type
if (tok->strAt(1) == ")" && Token::Match(tok->linkAt(1)->tokAt(-1), "%name%|]") &&
if (tok->strAt(1) == ")" && Token::Match(tok->linkAt(1)->tokAt(-1), "%name%|]") && !tok->linkAt(1)->tokAt(-1)->isKeyword() &&
TokenList::isFunctionHead(tok->linkAt(1), "{|;")) {
tok = tok->tokAt(3);
continue;
Expand Down
16 changes: 16 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TestVarID : public TestFixture {
TEST_CASE(varid7);
TEST_CASE(varidReturn1);
TEST_CASE(varidReturn2);
TEST_CASE(varidReturn3);
TEST_CASE(varid8);
TEST_CASE(varid9);
TEST_CASE(varid10);
Expand Down Expand Up @@ -517,6 +518,21 @@ class TestVarID : public TestFixture {
ASSERT_EQUALS(expected, actual);
}

void varidReturn3() {
const std::string actual = tokenize(
"struct S { int i; };\n"
"int f(S s) {\n"
" return (&s)->i;\n"
"}\n");

const char expected[] = "1: struct S { int i@1 ; } ;\n"
"2: int f ( S s@2 ) {\n"
"3: return ( & s@2 ) . i@3 ;\n"
"4: }\n";

ASSERT_EQUALS(expected, actual);
}

void varid8() {
const std::string actual = tokenize(
"void func()\n"
Expand Down

0 comments on commit 1439297

Please sign in to comment.