Skip to content

Commit f203219

Browse files
dmcppcheckclaude
andcommitted
The hide set of a token holds macro names instead of Macro pointers
The names are what Prosser's algorithm uses, and they can not dangle after #undef. No behaviour change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2677821 commit f203219

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

‎simplecpp.cpp‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ namespace simplecpp {
20062006
if (output2.cfront() != output2.cback() && macro2tok->str() == this->name())
20072007
break;
20082008
const MacroMap::const_iterator macro = macros.find(macro2tok->str());
2009-
if (macro == macros.end() || !macro->second.functionLike() || macro2tok->isInHideSet(&macro->second))
2009+
if (macro == macros.end() || !macro->second.functionLike() || macro2tok->isInHideSet(macro->first))
20102010
break;
20112011
TokenList rawtokens2(inputFiles);
20122012
const Location loc(macro2tok->location);
@@ -2118,7 +2118,7 @@ namespace simplecpp {
21182118
if (replaced)
21192119
tok->macro = nameTokDef->str();
21202120
if (expandedFromToken) {
2121-
tok->setHideSet(expandedFromToken, this);
2121+
tok->setHideSet(expandedFromToken, name());
21222122
tok->whitespaceahead = expandedFromToken->whitespaceahead;
21232123
}
21242124
return tok;
@@ -2508,7 +2508,7 @@ namespace simplecpp {
25082508
const MacroMap::const_iterator it = macros.find(temp.cback()->str());
25092509
if (it == macros.end() || expandedmacros.find(temp.cback()->str()) != expandedmacros.end())
25102510
return nullptr;
2511-
if (!it->second.functionLike() || temp.cback()->isInHideSet(&it->second))
2511+
if (!it->second.functionLike() || temp.cback()->isInHideSet(it->first))
25122512
return nullptr;
25132513
return &it->second;
25142514
}
@@ -2604,7 +2604,7 @@ namespace simplecpp {
26042604

26052605
output.push_back(newMacroToken(tok->str(), loc, true, tok));
26062606
if (it != macros.end())
2607-
output.back()->addToHideSet(&it->second);
2607+
output.back()->addToHideSet(it->first);
26082608
return tok->next;
26092609
}
26102610

@@ -2680,7 +2680,7 @@ namespace simplecpp {
26802680
const Token * const argEnd = parametertokens[argnr + 1U];
26812681
for (const Token *partok = parametertokens[argnr]->next; partok != argEnd;) {
26822682
const MacroMap::const_iterator it = macros.find(partok->str());
2683-
if (it != macros.end() && !partok->isInHideSet(&it->second) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end())) {
2683+
if (it != macros.end() && !partok->isInHideSet(it->first) && (partok->str() == name() || expandedmacros.find(partok->str()) == expandedmacros.end())) {
26842684
std::set<TokenString> expandedmacros2(expandedmacros); // temporary amnesia to allow reexpansion of currently expanding macros during argument evaluation
26852685
expandedmacros2.erase(name());
26862686
TokenList temp(files);

‎simplecpp.h‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ namespace simplecpp {
117117
};
118118
#endif // defined(__cpp_lib_string_view) && !defined(__cpp_lib_span)
119119

120-
class Macro;
121-
122120
/**
123121
* Location in source code
124122
*/
@@ -212,17 +210,17 @@ namespace simplecpp {
212210

213211
/**
214212
* The hide set holds the macros that this token must not be expanded into.
215-
* Set it to the hide set of tok, with m added.
213+
* Set it to the hide set of tok, with the macro macroName added.
216214
*/
217-
void setHideSet(const Token *tok, const Macro* m) {
215+
void setHideSet(const Token *tok, const TokenString &macroName) {
218216
mHideSet = tok->mHideSet;
219-
mHideSet.insert(m);
217+
mHideSet.insert(macroName);
220218
}
221-
bool isInHideSet(const Macro* m) const {
222-
return mHideSet.find(m) != mHideSet.end();
219+
bool isInHideSet(const TokenString &macroName) const {
220+
return mHideSet.find(macroName) != mHideSet.end();
223221
}
224-
void addToHideSet(const Macro* m) {
225-
mHideSet.insert(m);
222+
void addToHideSet(const TokenString &macroName) {
223+
mHideSet.insert(macroName);
226224
}
227225

228226
void printAll() const;
@@ -238,7 +236,7 @@ namespace simplecpp {
238236

239237
TokenString string;
240238

241-
std::set<const Macro*> mHideSet;
239+
std::set<TokenString> mHideSet;
242240
};
243241

244242
/** Output from preprocessor */

0 commit comments

Comments
 (0)