diff --git a/.gitignore b/.gitignore index f73b2526..b6b1a044 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ tmp .ninja_* *.ninja compile_commands.json -dub_describe.json \ No newline at end of file +dub_describe.json +*.lst \ No newline at end of file diff --git a/source/dpp/translation/macro_.d b/source/dpp/translation/macro_.d index 4272a693..6ad274a2 100644 --- a/source/dpp/translation/macro_.d +++ b/source/dpp/translation/macro_.d @@ -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 diff --git a/tests/it/issues.d b/tests/it/issues.d index ea7a120c..0d393809 100644 --- a/tests/it/issues.d +++ b/tests/it/issues.d @@ -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 { @@ -947,7 +953,11 @@ unittest { #define BAR 33 // before the BAR macro, BAR is 42. After, it's 33. `, - D(""), // no need for .dpp source code + D( + q{ + // the macro is what works here + static assert(BAR == 33); + }), ); writeFile("2nd.h", ` @@ -956,7 +966,9 @@ unittest { // The bug had to do with ordering. enum TheEnum { BAR = 42 }; `); - run("-c", inSandboxPath("app.dpp"), "--keep-pre-cpp-files"); + + runPreprocessOnly("app.dpp", "--scoped-enums"); + shouldCompile("app.d"); } }