fix Issue 23622 - ImportC #defines conflict with declarations

This commit is contained in:
Walter Bright 2023-01-13 00:30:20 -08:00 committed by The Dlang Bot
parent 0a7502f206
commit e32f665190
6 changed files with 20 additions and 0 deletions

View file

@ -5306,6 +5306,8 @@ final class CParser(AST) : Parser!AST
void addVar(AST.VarDeclaration v)
{
//printf("addVar() %s\n", v.toChars());
v.isCmacro(true); // mark it as coming from a C #define
/* If it's already defined, replace the earlier
* definition
*/

View file

@ -1148,6 +1148,7 @@ extern (C++) class VarDeclaration : Declaration
bool doNotInferReturn; /// do not infer 'return' for this variable
bool isArgDtorVar; /// temporary created to handle scope destruction of a function argument
bool isCmacro; /// it is a C macro turned into a C declaration
}
import dmd.common.bitfields : generateBitFields;

View file

@ -270,6 +270,8 @@ public:
bool doNotInferReturn(bool v);
bool isArgDtorVar() const; // temporary created to handle scope destruction of a function argument
bool isArgDtorVar(bool v);
bool isCmacro() const; // if a C macro turned into a C variable
bool isCmacro(bool v);
static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
VarDeclaration *syntaxCopy(Dsymbol *) override;
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;

View file

@ -2620,6 +2620,12 @@ Dsymbol handleSymbolRedeclarations(ref Scope sc, Dsymbol s, Dsymbol s2, ScopeDsy
auto vd = s.isVarDeclaration(); // new declaration
auto vd2 = s2.isVarDeclaration(); // existing declaration
if (vd && vd.isCmacro())
return vd2;
assert(!(vd2 && vd2.isCmacro()));
if (vd && vd2)
{
/* if one is `static` and the other isn't, the result is undefined

View file

@ -5944,6 +5944,8 @@ public:
bool doNotInferReturn(bool v);
bool isArgDtorVar() const;
bool isArgDtorVar(bool v);
bool isCmacro() const;
bool isCmacro(bool v);
private:
uint16_t bitFields;
public:

View file

@ -0,0 +1,7 @@
// https://issues.dlang.org/show_bug.cgi?id=23622
int FP_NAN = 0;
#define FP_NAN 0
enum E { ENUM = 0 };
#define ENUM 0