From 3c649dc8c611fa3ee3901586b18d9a4799ee5b9f Mon Sep 17 00:00:00 2001 From: Atila Neves Date: Thu, 30 May 2024 12:28:58 -0500 Subject: [PATCH 1/3] Ignore lst files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From 915f0da73ca4855ccc123ec2948dc9f761c78ffe Mon Sep 17 00:00:00 2001 From: Atila Neves Date: Wed, 5 Jun 2024 16:07:23 -0500 Subject: [PATCH 2/3] Better test for #79 --- tests/it/issues.d | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/it/issues.d b/tests/it/issues.d index ea7a120c..ffded030 100644 --- a/tests/it/issues.d +++ b/tests/it/issues.d @@ -947,7 +947,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 +960,8 @@ unittest { // The bug had to do with ordering. enum TheEnum { BAR = 42 }; `); - run("-c", inSandboxPath("app.dpp"), "--keep-pre-cpp-files"); + runPreprocessOnly("app.dpp"); + shouldCompile("app.d"); } } From 3a01aa934ef90c206ce5f490993ac4233b98c18c Mon Sep 17 00:00:00 2001 From: Atila Neves Date: Wed, 5 Jun 2024 16:19:08 -0500 Subject: [PATCH 3/3] Drop static ifs before macro translations to avoid compiler issues --- source/dpp/translation/macro_.d | 11 ++++++----- tests/it/issues.d | 9 ++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) 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 ffded030..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 { @@ -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"); } }