December 12, 2023
https://issues.dlang.org/show_bug.cgi?id=24280

          Issue ID: 24280
           Summary: ImportC: forward reference error when compiling
                    multiple files
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: dkorpel@live.nl

I have two single-file c libraries, and dmd can compile either one just fine, but not at the same time. Reduced example:

a.c:
```C
struct timespec
{
    int s;
};
```

b.c:
```C
struct S;

struct timespec
{
    int s;
};

typedef struct timespec Clock;

Clock now()
{
    Clock result;
    return result;
}

struct S
{
    Clock clock;
};
```

```
dmd a.c // works
dmd b.c // works
dmd b.c a.c // works
dmd a.c b.c // fails:
b.c(13): Error: forward reference to type `timespec`
```

It's very fragile, sometimes the error goes away when removing a random unused macro `#define _POSIX_C_SOURCE 200112L` or changing an identifier name (I can't rename `timespec`), but it does seem deterministic: I get the error every time as long as the input stays the same.

--