Skip to content

Commit 306faa9

Browse files
dmcppcheckclaude
andcommitted
Token::setExpandedFrom() only updates the expanded-from set
The whitespace is copied in Macro::newMacroToken() instead. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3bd22f4 commit 306faa9

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,13 +2105,22 @@ namespace simplecpp {
21052105
}
21062106
};
21072107
private:
2108-
/** Create new token where Token::macro is set for replaced tokens */
2108+
/**
2109+
* Create a new token in the expansion of this macro.
2110+
* @param str the token text
2111+
* @param loc the location
2112+
* @param replaced Token::macro is set to the name of this macro
2113+
* @param expandedFromToken if not null, the new token copies its "expanded from" set and
2114+
* its whitespace, and this macro is added to the set
2115+
*/
21092116
Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced, const Token *expandedFromToken=nullptr) const {
21102117
auto *tok = new Token(str,loc);
21112118
if (replaced)
21122119
tok->macro = nameTokDef->str();
2113-
if (expandedFromToken)
2120+
if (expandedFromToken) {
21142121
tok->setExpandedFrom(expandedFromToken, this);
2122+
tok->whitespaceahead = expandedFromToken->whitespaceahead;
2123+
}
21152124
return tok;
21162125
}
21172126

‎simplecpp.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,10 @@ namespace simplecpp {
210210
return tok;
211211
}
212212

213+
/** Copy the "expanded from" set of tok, and add m */
213214
void setExpandedFrom(const Token *tok, const Macro* m) {
214215
mExpandedFrom = tok->mExpandedFrom;
215216
mExpandedFrom.insert(m);
216-
if (tok->whitespaceahead)
217-
whitespaceahead = true;
218217
}
219218
bool isExpandedFrom(const Macro* m) const {
220219
return mExpandedFrom.find(m) != mExpandedFrom.end();

0 commit comments

Comments
 (0)