Skip to content

Commit

Permalink
fixed #387 - do not undefine source-level defines via -U
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Nov 22, 2024
1 parent 0ab783c commit 4564ff6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
12 changes: 5 additions & 7 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3445,13 +3445,11 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
continue;
try {
const Macro &macro = Macro(rawtok->previous, files);
if (dui.undefined.find(macro.name()) == dui.undefined.end()) {
const MacroMap::iterator it = macros.find(macro.name());
if (it == macros.end())
macros.insert(std::pair<TokenString, Macro>(macro.name(), macro));
else
it->second = macro;
}
const MacroMap::iterator it = macros.find(macro.name());
if (it == macros.end())
macros.insert(std::pair<TokenString, Macro>(macro.name(), macro));
else
it->second = macro;
} catch (const std::runtime_error &) {
if (outputList) {
simplecpp::Output err(files);
Expand Down
13 changes: 13 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,18 @@ static void userdef()
ASSERT_EQUALS("\n123", preprocess(code, dui));
}

static void userundef_src()
{
const char code[] =
"#define A\n"
"#ifdef A\n"
"123\n"
"#endif\n";
simplecpp::DUI dui;
dui.undefined.insert("A");
ASSERT_EQUALS("\n\n123", preprocess(code, dui));
}

static void utf8()
{
ASSERT_EQUALS("123", readfile("\xEF\xBB\xBF 123"));
Expand Down Expand Up @@ -3124,6 +3136,7 @@ int main(int argc, char **argv)
TEST_CASE(undef);

TEST_CASE(userdef);
TEST_CASE(userundef_src);

// utf/unicode
TEST_CASE(utf8);
Expand Down

0 comments on commit 4564ff6

Please sign in to comment.