Skip to content

Commit

Permalink
Drop static ifs before macro translations to avoid compiler issues
Browse files Browse the repository at this point in the history
  • Loading branch information
atilaneves committed Jun 5, 2024
1 parent 915f0da commit 3a01aa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 6 additions & 5 deletions source/dpp/translation/macro_.d
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ string[] translateMacro(in from!"clang".Cursor cursor,
];
}
}

return [
`#ifdef ` ~ spelling,
`# undef ` ~ spelling,
`#endif`,
`static if(!is(typeof(` ~ spelling ~ `))) {`,
] ~ ret ~ [
`}`,
`#define ` ~ spelling ~ ` ` ~ translation.dcode,
];
] ~
ret ~
[
`#define ` ~ spelling ~ ` ` ~ translation.dcode,
];
}

// Define a template function with the same name as the macro
Expand Down
9 changes: 8 additions & 1 deletion tests/it/issues.d
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,12 @@ version(linux) // linux specific header in the test
}
}

// the original fix for this issue had to do with ordering, but it
// also ended up guarding a `static if` that checked if a macro
// already existed before trying to define it again. Unfortunately,
// too many static ifs caused the compiler to have ordering problems,
// but removing that caused this test to fail. The "fix" is to ask for
// scoped enums so that it doesn't try to define `BAR` twice.
@Tags("issue")
@("79")
unittest {
Expand All @@ -960,7 +966,8 @@ unittest {
// The bug had to do with ordering.
enum TheEnum { BAR = 42 };
`);
runPreprocessOnly("app.dpp");

runPreprocessOnly("app.dpp", "--scoped-enums");
shouldCompile("app.d");
}
}
Expand Down

0 comments on commit 3a01aa9

Please sign in to comment.