@@ -1187,7 +1187,7 @@ Dsymbol toAlias2(Dsymbol s)
11871187{
11881188 if (auto ad = s.isAliasDeclaration())
11891189 {
1190- if (ad.inuse)
1190+ if (ad.inuse && ! ad.isCmacro) // c amcro can refer to itself and compile
11911191 {
11921192 .error(ad.loc, " %s `%s` recursive alias declaration" , ad.kind, ad.toPrettyChars);
11931193 return ad;
@@ -1262,7 +1262,7 @@ private Dsymbol toAliasImpl(AliasDeclaration ad)
12621262 ad.inuse = 0 ;
12631263 }
12641264 }
1265- if (ad.inuse)
1265+ if (ad.inuse && ! ad.isCmacro) // C macros can refer to itself and comoile
12661266 {
12671267 .error(ad.loc, " %s `%s` recursive alias declaration" , ad.kind, ad.toPrettyChars);
12681268 return err ();
@@ -5825,8 +5825,9 @@ private extern(C++) class AddMemberVisitor : Visitor
58255825 }
58265826
58275827 // If using C tag/prototype/forward declaration rules
5828+ // remember, C allows rdececlarations of macros too
5829+ // (!sc.inCfie && dsym.isAliasDeclaration().isCmacro && s2.isAliasDeclaration().isCmacro)))
58285830 if (sc && sc.inCfile && ! dsym.isImport())
5829- // When merging master, replace with: if (sc && sc.inCfile && !dsym.isImport())
58305831 {
58315832 if (handleTagSymbols(* sc, dsym, s2, sds))
58325833 return ;
@@ -6328,15 +6329,30 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc)
63286329 // Detect `alias sym = sym;` to prevent creating loops in overload overnext lists.
63296330 if (auto tident = ds.type.isTypeIdentifier())
63306331 {
6331- if (sc.hasEdition(Edition.v2024) && tident.idents.length)
6332+ if (( sc.hasEdition(Edition.v2024) && tident.idents.length) || ds.isCmacro )
63326333 {
63336334 alias mt = tident;
63346335 Dsymbol pscopesym;
63356336 Dsymbol s = sc.search(ds.loc, mt.ident, pscopesym);
6337+ /* if the imported macro from C doesn't exist,
6338+ * probably a builtin one we don't define
6339+ * stop processing it. C macro refering identifiers
6340+ * can point to absolutely anything either defined or not
6341+ * #ifdefine hsgshsh hsshhshs is a valid C compile but emit on usage
6342+ * then we implement the ones we need
6343+ */
6344+ if (! s && sc.inCfile && ds.isCmacro)
6345+ {
6346+ ds.aliassym = null ;
6347+ ds.errors = false ; // no error flag
6348+ ds.semanticRun = PASS .semanticdone; // mark semantic as complete
6349+ ds.inuse = 0 ; // clear recursion flag
6350+ return ;
6351+ }
63366352 // detect `alias a = var1.member_var;` which confusingly resolves to
63376353 // `typeof(var1).member_var`, which can be valid inside the aggregate type
63386354 if (s && s.isVarDeclaration() &&
6339- mt.ident != Id.This && mt.ident != Id._super)
6355+ mt.ident != Id.This && mt.ident != Id._super && ( ! ds.isCmacro && ! sc.inCfile)) // don't let a C macro alias pass here
63406356 {
63416357 s = tident.toDsymbol(sc);
63426358 // don't error for `var1.static_symbol`
@@ -6350,7 +6366,7 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc)
63506366 }
63516367 }
63526368 // Selective imports are allowed to alias to the same name `import mod : sym=sym`.
6353- if (! ds._import)
6369+ if (! ds._import && ( ! ds.isCmacro && ! sc.inCfile)) // C identifier macros are not allowed here
63546370 {
63556371 if (tident.ident is ds.ident && ! tident.idents.length)
63566372 {
0 commit comments