Bug 24718 – [ImportC] typedef struct with name as a pointer cannot be used with struct name

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-08-24T22:15:08Z
Last change time
2024-12-13T19:36:59Z
Keywords
ImportC
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#20499 →

Comments

Comment #0 by schveiguy — 2024-08-24T22:15:08Z
imported.c: typedef struct Foo { int x; } *pFoo; struct Bar { struct Foo foo; }; main.d: import imported; Compiling main.d fails to build with the following message: imported.c(6): Error: variable `testimportc.Bar.foo` - no definition of struct `Foo` imported.c(6): see https://dlang.org/spec/struct.html#opaque_struct_unions imported.c(6): perhaps declare a variable with pointer type `Foo*` instead Actually compiling imported.c with the D compiler succeeds! Note that it *requires* a typedef to a pointer, with a struct name. Removing the pointer, it works. Removing the typedef, it works. Note that I discovered this on a Mac via ldc, but I believe this is not limited to those.
Comment #1 by schveiguy — 2024-08-30T15:05:33Z
From the forum post: https://forum.dlang.org/post/[email protected] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): Error: variable `lib_test.mach_vm_range_recipe_v1_t.range` - no definition of struct `mach_vm_range` /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): see https://dlang.org/spec/struct.html#opaque_struct_unions /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/vm_types.h(168): perhaps declare a variable with pointer type `mach_vm_range*` instead This is actually the error I encountered as well. I wanted to put it in a comment so those looking for the error will find this issue. I boiled the problem down to this simple reproduction.
Comment #2 by robert.schadek — 2024-12-13T19:36:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20499 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB