Skip to content

Fix #23143 - importC: translate function alias macros to aliases#23214

Draft
dkorpel wants to merge 1 commit into
dlang:masterfrom
dkorpel:fix23143-importc-alias-macros
Draft

Fix #23143 - importC: translate function alias macros to aliases#23214
dkorpel wants to merge 1 commit into
dlang:masterfrom
dkorpel:fix23143-importc-alias-macros

Conversation

@dkorpel
Copy link
Copy Markdown
Contributor

@dkorpel dkorpel commented Jun 3, 2026

Closes #23143

Recognize #define ID identifier and define an alias if identifier was seen before.

@dkorpel dkorpel added the Feature:ImportC Pertaining to ImportC support label Jun 3, 2026
@dkorpel dkorpel force-pushed the fix23143-importc-alias-macros branch from 5ff53a6 to fe78287 Compare June 3, 2026 12:33
A `#define ID identifier` whose body is a single identifier naming a
function (e.g. `#define mpz_init __gmpz_init` in gmp.h) was abandoned,
leaving the macro name undefined in D. Translate such object-like
macros to `alias ID = identifier;` so they resolve to the function.

Restricted to identifiers that name a function declared in the same
translation unit:
 - aliasing an undefined identifier would error eagerly, which system
   headers would trigger by #define-ing keywords to compiler builtins
   (e.g. `#define complex _Complex`);
 - aliasing a type or variable would shadow declarations with a
   conflicting meaning (e.g. C's `complex`, glibc's `#define stdin stdin`).
Self-referential macros are skipped as well.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dkorpel dkorpel force-pushed the fix23143-importc-alias-macros branch from fe78287 to 5f00849 Compare June 3, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:ImportC Pertaining to ImportC support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

importC fails to translate function alias macros

1 participant