mirror of
https://github.com/dlang/dmd.git
synced 2025-04-28 14:10:11 +03:00
fix Issue 23622 - ImportC #defines conflict with declarations
This commit is contained in:
parent
0a7502f206
commit
e32f665190
6 changed files with 20 additions and 0 deletions
|
@ -5306,6 +5306,8 @@ final class CParser(AST) : Parser!AST
|
||||||
|
|
||||||
void addVar(AST.VarDeclaration v)
|
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
|
/* If it's already defined, replace the earlier
|
||||||
* definition
|
* definition
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1148,6 +1148,7 @@ extern (C++) class VarDeclaration : Declaration
|
||||||
bool doNotInferReturn; /// do not infer 'return' for this variable
|
bool doNotInferReturn; /// do not infer 'return' for this variable
|
||||||
|
|
||||||
bool isArgDtorVar; /// temporary created to handle scope destruction of a function argument
|
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;
|
import dmd.common.bitfields : generateBitFields;
|
||||||
|
|
|
@ -270,6 +270,8 @@ public:
|
||||||
bool doNotInferReturn(bool v);
|
bool doNotInferReturn(bool v);
|
||||||
bool isArgDtorVar() const; // temporary created to handle scope destruction of a function argument
|
bool isArgDtorVar() const; // temporary created to handle scope destruction of a function argument
|
||||||
bool isArgDtorVar(bool v);
|
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);
|
static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
|
||||||
VarDeclaration *syntaxCopy(Dsymbol *) override;
|
VarDeclaration *syntaxCopy(Dsymbol *) override;
|
||||||
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;
|
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;
|
||||||
|
|
|
@ -2620,6 +2620,12 @@ Dsymbol handleSymbolRedeclarations(ref Scope sc, Dsymbol s, Dsymbol s2, ScopeDsy
|
||||||
|
|
||||||
auto vd = s.isVarDeclaration(); // new declaration
|
auto vd = s.isVarDeclaration(); // new declaration
|
||||||
auto vd2 = s2.isVarDeclaration(); // existing declaration
|
auto vd2 = s2.isVarDeclaration(); // existing declaration
|
||||||
|
|
||||||
|
if (vd && vd.isCmacro())
|
||||||
|
return vd2;
|
||||||
|
|
||||||
|
assert(!(vd2 && vd2.isCmacro()));
|
||||||
|
|
||||||
if (vd && vd2)
|
if (vd && vd2)
|
||||||
{
|
{
|
||||||
/* if one is `static` and the other isn't, the result is undefined
|
/* if one is `static` and the other isn't, the result is undefined
|
||||||
|
|
|
@ -5944,6 +5944,8 @@ public:
|
||||||
bool doNotInferReturn(bool v);
|
bool doNotInferReturn(bool v);
|
||||||
bool isArgDtorVar() const;
|
bool isArgDtorVar() const;
|
||||||
bool isArgDtorVar(bool v);
|
bool isArgDtorVar(bool v);
|
||||||
|
bool isCmacro() const;
|
||||||
|
bool isCmacro(bool v);
|
||||||
private:
|
private:
|
||||||
uint16_t bitFields;
|
uint16_t bitFields;
|
||||||
public:
|
public:
|
||||||
|
|
7
compiler/test/compilable/test23622.c
Normal file
7
compiler/test/compilable/test23622.c
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue