Bug 23622 – ImportC #defines conflict with declarations
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-01-12T09:54:09Z
Last change time
2023-01-14T12:38:15Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Krzysztof Jajeśnica
Comments
Comment #0 by krzysztof.jajesnica — 2023-01-12T09:54:09Z
The following C code fails to compile with DMD 2.101.1:
#include <math.h>
float norm2D(float x, float y) {
return sqrt(x*x + y*y);
}
DMD error message:
#defines(1074): Error: variable `vec_math.FP_NAN` conflicts with enum member `__anonymous.FP_NAN` at /usr/include/math.h(936)
#defines(1075): Error: variable `vec_math.FP_INFINITE` conflicts with enum member `__anonymous.FP_INFINITE` at /usr/include/math.h(939)
#defines(1076): Error: variable `vec_math.FP_ZERO` conflicts with enum member `__anonymous.FP_ZERO` at /usr/include/math.h(942)
#defines(1077): Error: variable `vec_math.FP_SUBNORMAL` conflicts with enum member `__anonymous.FP_SUBNORMAL` at /usr/include/math.h(945)
#defines(1078): Error: variable `vec_math.FP_NORMAL` conflicts with enum member `__anonymous.FP_NORMAL` at /usr/include/math.h(948)
The problem seems to be caused by this strange enum declaration in math.h:
enum
{
FP_NAN =
# define FP_NAN 0
FP_NAN,
FP_INFINITE =
# define FP_INFINITE 1
FP_INFINITE,
FP_ZERO =
# define FP_ZERO 2
FP_ZERO,
FP_SUBNORMAL =
# define FP_SUBNORMAL 3
FP_SUBNORMAL,
FP_NORMAL =
# define FP_NORMAL 4
FP_NORMAL
};
Comment #1 by bugzilla — 2023-01-13T00:37:27Z
What's happening is ImportC sees those macro definitions and transforms them into manifest constant declarations. Those declarations then conflict with the enum declarations.
Comment #2 by bugzilla — 2023-01-13T08:28:17Z
A reduced test case:
enum { FP_NAN = 0 };
#define FP_NAN 0
Comment #3 by dlang-bot — 2023-01-13T08:32:52Z
@WalterBright created dlang/dmd pull request #14811 "fix Issue 23622 - ImportC #defines conflict with declarations" fixing this issue:
- fix Issue 23622 - ImportC #defines conflict with declarations
https://github.com/dlang/dmd/pull/14811
Comment #4 by dlang-bot — 2023-01-14T00:41:43Z
dlang/dmd pull request #14811 "fix Issue 23622 - ImportC #defines conflict with declarations" was merged into master:
- 6ad91b95ce902a86199b234117b58bc48d14710a by Walter Bright:
fix Issue 23622 - ImportC #defines conflict with declarations
https://github.com/dlang/dmd/pull/14811