atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
231 stars 31 forks source link

(Issue or wish) Some versions of libclang on Windows silently ignores typedef of anonymous structs #322

Open denizzzka opened 1 year ago

denizzzka commented 1 year ago

libclang ver > (approx) 11.1.0 (and further above 16) only(!) on Windows silently ignores typedefs of anonymous structs like:

typedef struct { int i; } Foo;

as result, after parsing .dpp file like that:

#include "main.h"

void main() {}

unittest
{
    Foo f;
    f.i = 42;
    static assert(!__traits(compiles, _Anonymous_1(42)));
}

d++ returns only:

extern(C)
{
}

[...]

without Foo payload. I.e., it just skips constructions like this and not reports anything about.

I don't know why it is occurs, but it was very difficult to understand what this occurs because on Linux same header code works as it was intended and clang.exe on Windows also compiles this code as well, without any errors or warnings. Code like this also works fine:

typedef struct Foo { int i; } Foo;

All this cases is already covered by integration tests.

But I wish, at least, ask to add appropriate libclang version check into d++ and also add flag (like --ignore-libclang-version) for ignore this behaviour

denizzzka commented 1 year ago

Addition:

Command to reproduce:

dub run dpp -- parsing.dpp --preprocess-only --hard-fail

dpp vresion ~master was used

Switching to C++ (--parse-as-cpp) also solves problem, but may add anothers, thus, can't be considered as solution