atilaneves / dpp

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

Error: declaration expected, not `#` on macOS with default cpp #316

Closed tom-tan closed 1 year ago

tom-tan commented 1 year ago

It only happens on macOS with cpp that is bundled in XCode. Here are codes to reproduce this issue.

define DEF_VAL 0

endif


- issue.dpp
```d
#include "issue.h"

void main() {}

How to reproduce

$ dub run -q dpp -- --ignore-system-paths --preprocess-only issue.dpp
$ dmd -run issue.d

Expected behavior

The above commands are successfully executed.

Actual behavior

dmd -run fails with the following messages:

$ dmd -run issue.d
issue.d(57): Error: declaration expected, not `#`
issue.d(67): Error: unmatched closing brace

Note

I reproduce it on Github Actions with this configuration. Here is a difference between clang-cpp (used in Github Actions for dpp) and /usr/bin/cpp (default cpp on Github Actions).

} ...


- preprocessed by `cpp` ([result of Github Actions](https://github.com/tom-tan/dpp/runs/8076609723?check_suite_focus=true#step:6:67))
```d
...
extern(C)
{

    #ifdef DEF_VAL

    #endif
    static if(!is(typeof(DEF_VAL))) {
        private enum enumMixinStr_DEF_VAL = `enum DEF_VAL = 0;`;
        static if(is(typeof({ mixin(enumMixinStr_DEF_VAL); }))) {
            mixin(enumMixinStr_DEF_VAL);
        }
    }

}
...

It would be nice if dpp can work with /usr/bin/cpp.