Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #13155: Tokenizer::simplifyTypedef does not set info correctly for typedef in function #6888

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,14 @@ Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last,
std::stack<Token *> links;
Token *tok2 = dest;
int linenr = dest->linenr();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks inconsistent. we read linenr from dest but column from dest->next().
should there be some more option for the location?

int column = dest->next() ? dest->next()->column() : dest->column() + dest->str().length() + 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the dest->column() + dest->str().length() + 1 is unfortunate. It's an educated guess but could be very wrong.

const int commonFileIndex = dest->fileIndex();
for (const Token *tok = first; tok != last->next(); tok = tok->next()) {
tok2->insertToken(tok->str());
tok2 = tok2->next();
tok2->fileIndex(commonFileIndex);
tok2->linenr(linenr);
tok2->column(column);
tok2->tokType(tok->tokType());
tok2->flags(tok->flags());
tok2->varId(tok->varId());
Expand All @@ -292,6 +294,9 @@ Token *TokenList::copyTokens(Token *dest, const Token *first, const Token *last,

links.pop();
}

column += tok->next() ? tok->next()->column() - tok->column() : tok->str().length() + 1;
Copy link
Owner

@danmar danmar Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not so sure about this. At least when we replace a token it's better that the column just match the replaced token. imagine MY_INT generates a warning the warning should point at MY_INT not at some other location later..


if (!one_line && tok->next())
linenr += tok->next()->linenr() - tok->linenr();
}
Expand Down
Loading