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

fixed #387 - do not undefine source-level defines via -U #390

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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