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

@dkorpel dkorpel commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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 2 times, most recently from fe78287 to 5f00849 Compare June 3, 2026 14:18
@xoxorwr

xoxorwr commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This should not restrict it to functions.

Same issue with:

struct __private_struct{};
#define public_type __private_struct

A `#define ID identifier` whose body is a single declared identifier
(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/type/variable.

The target must be declared in the same translation unit (or an earlier
#define): aliasing an undefined identifier would error eagerly, which
system headers trigger by #define-ing keywords to compiler builtins
(e.g. `#define __func__ __FUNCTION__`, `#define __restrict restrict`).
Self-referential macros (glibc's `#define stdin stdin`) are skipped, as
they would otherwise shadow the declaration they name.

On Windows the C library's `complex` macro resolves to a struct, which
ImportC now aliases; druntime's `core.stdc.complex.complex` is an alias
of `creal`, so importc_compare flags the expected size difference - add
it to that test's known problems.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dkorpel dkorpel force-pushed the fix23143-importc-alias-macros branch from 5f00849 to cf67313 Compare June 5, 2026 12:31
@dlang-bot

Copy link
Copy Markdown

Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#23214"

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

4 participants