From 292019346b87b501042f108ee405b57422f01e61 Mon Sep 17 00:00:00 2001 From: drpriver Date: Mon, 14 Apr 2025 01:37:38 -0700 Subject: [PATCH] Fix 21225: ImportC: macro interpreted as an enum conflicts with function (#21228) Fixes https://github.com/dlang/dmd/issues/21225 Don't let C macro variable declarations shadow any symbol. --- compiler/src/dmd/importc.d | 2 +- compiler/test/compilable/test21225.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 compiler/test/compilable/test21225.c diff --git a/compiler/src/dmd/importc.d b/compiler/src/dmd/importc.d index dcd6bb1d40..d3381dc858 100644 --- a/compiler/src/dmd/importc.d +++ b/compiler/src/dmd/importc.d @@ -548,7 +548,7 @@ Dsymbol handleSymbolRedeclarations(ref Scope sc, Dsymbol s, Dsymbol s2, ScopeDsy auto vd2 = s2.isVarDeclaration(); // existing declaration if (vd && vd.isCmacro()) - return vd2; + return s2; assert(!(vd2 && vd2.isCmacro())); diff --git a/compiler/test/compilable/test21225.c b/compiler/test/compilable/test21225.c new file mode 100644 index 0000000000..45eb5cd92f --- /dev/null +++ b/compiler/test/compilable/test21225.c @@ -0,0 +1,7 @@ +// https://github.com/dlang/dmd/issues/21225 +void x(void){ +} +#define x 3 + +typedef struct Foo {int y; } foo; +#define foo 3