mirror of
https://github.com/dlang/dmd.git
synced 2025-04-25 20:50:41 +03:00
Fixes https://github.com/dlang/dmd/issues/20502 Similar to VarDeclarations, don't let TemplateDeclarations from C defines shadow a real symbol.
This commit is contained in:
parent
e5de57e518
commit
5fd0d29211
6 changed files with 21 additions and 0 deletions
|
@ -6057,6 +6057,8 @@ final class CParser(AST) : Parser!AST
|
||||||
//printf("addSym() %s\n", s.toChars());
|
//printf("addSym() %s\n", s.toChars());
|
||||||
if (auto v = s.isVarDeclaration())
|
if (auto v = s.isVarDeclaration())
|
||||||
v.isCmacro(true); // mark it as coming from a C #define
|
v.isCmacro(true); // mark it as coming from a C #define
|
||||||
|
if (auto td = s.isTemplateDeclaration())
|
||||||
|
td.isCmacro = true; // mark as coming from a C #define
|
||||||
/* If it's already defined, replace the earlier
|
/* If it's already defined, replace the earlier
|
||||||
* definition
|
* definition
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -593,6 +593,7 @@ extern (C++) final class TemplateDeclaration : ScopeDsymbol
|
||||||
bool isTrivialAliasSeq; /// matches pattern `template AliasSeq(T...) { alias AliasSeq = T; }`
|
bool isTrivialAliasSeq; /// matches pattern `template AliasSeq(T...) { alias AliasSeq = T; }`
|
||||||
bool isTrivialAlias; /// matches pattern `template Alias(T) { alias Alias = qualifiers(T); }`
|
bool isTrivialAlias; /// matches pattern `template Alias(T) { alias Alias = qualifiers(T); }`
|
||||||
bool deprecated_; /// this template declaration is deprecated
|
bool deprecated_; /// this template declaration is deprecated
|
||||||
|
bool isCmacro; /// Whether this template is a translation of a C macro
|
||||||
Visibility visibility;
|
Visibility visibility;
|
||||||
|
|
||||||
// threaded list of previous instantiation attempts on stack
|
// threaded list of previous instantiation attempts on stack
|
||||||
|
|
|
@ -1749,6 +1749,7 @@ public:
|
||||||
bool isTrivialAliasSeq;
|
bool isTrivialAliasSeq;
|
||||||
bool isTrivialAlias;
|
bool isTrivialAlias;
|
||||||
bool deprecated_;
|
bool deprecated_;
|
||||||
|
bool isCmacro;
|
||||||
Visibility visibility;
|
Visibility visibility;
|
||||||
TemplatePrevious* previous;
|
TemplatePrevious* previous;
|
||||||
Expression* lastConstraint;
|
Expression* lastConstraint;
|
||||||
|
|
|
@ -544,6 +544,12 @@ Dsymbol handleSymbolRedeclarations(ref Scope sc, Dsymbol s, Dsymbol s2, ScopeDsy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't let macros shadow real symbols
|
||||||
|
if (auto td = s.isTemplateDeclaration())
|
||||||
|
{
|
||||||
|
if (td.isCmacro) return s2;
|
||||||
|
}
|
||||||
|
|
||||||
auto vd = s.isVarDeclaration(); // new declaration
|
auto vd = s.isVarDeclaration(); // new declaration
|
||||||
auto vd2 = s2.isVarDeclaration(); // existing declaration
|
auto vd2 = s2.isVarDeclaration(); // existing declaration
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ public:
|
||||||
d_bool isTrivialAliasSeq; // matches `template AliasSeq(T...) { alias AliasSeq = T; }
|
d_bool isTrivialAliasSeq; // matches `template AliasSeq(T...) { alias AliasSeq = T; }
|
||||||
d_bool isTrivialAlias; // matches pattern `template Alias(T) { alias Alias = qualifiers(T); }`
|
d_bool isTrivialAlias; // matches pattern `template Alias(T) { alias Alias = qualifiers(T); }`
|
||||||
d_bool deprecated_; // this template declaration is deprecated
|
d_bool deprecated_; // this template declaration is deprecated
|
||||||
|
d_bool isCmacro; // Whether this template is a translation of a C macro
|
||||||
Visibility visibility;
|
Visibility visibility;
|
||||||
|
|
||||||
TemplatePrevious *previous; // threaded list of previous instantiation attempts on stack
|
TemplatePrevious *previous; // threaded list of previous instantiation attempts on stack
|
||||||
|
|
10
compiler/test/compilable/test20502.c
Normal file
10
compiler/test/compilable/test20502.c
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// https://github.com/dlang/dmd/issues/20502
|
||||||
|
struct mg_str {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
void mg_str_s() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#define mg_str(s) mg_str_s(s)
|
Loading…
Add table
Add a link
Reference in a new issue