Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHNT #if directives causes "token is not a valid binary operator in a preprocessor subexpression" #570

Open
dongle-the-gadget opened this issue Aug 25, 2024 · 4 comments

Comments

@dongle-the-gadget
Copy link

dongle-the-gadget commented Aug 25, 2024

PHNT includes some #if directives that look like below, and that causes ClangSharpPInvokeGenerator to output "token is not a valid binary operator in a preprocessor subexpression":

#define PHNT_MODE_KERNEL 0

#ifndef PHNT_MODE
#define PHNT_MODE 1
#endif

#if (PHNT_MODE != PHNT_MODE_KERNEL)
// Some real code here
#endif
@tannergooding
Copy link
Member

Can you provide some more details about the options you're passing into ClangSharp, the version you're using, and possibly a minimal repro?

ClangSharp simply passes the files down to Clang. So if Clang is reporting an error then it's likely caused by some other mismatch.

@dongle-the-gadget
Copy link
Author

I'm using ClangSharpPInvokeGenerator version 18.1.0.1.

RSP file:

--file
test.h
--output
Test
--namespace
Test
--define-macro
PHNT_MODE PHNT_MODE_KERNEL

As for the test.h file, the code in the original comment should work as-is to reproduce the error.

@tannergooding
Copy link
Member

tannergooding commented Aug 26, 2024

You've defined PHNT_MODE with no value, so it compiles down to #if ( != 0)

You need to either not do --define-macro because it's automatically included in the file, or explicitly give it a value such as PHNT_MODE=1

@tannergooding
Copy link
Member

You can reproduce this in isolation on godbolt using something like:

#define PHNT_MODE
#define PHNT_MODE_KERNEL

#define PHNT_MODE_KERNEL 0

#ifndef PHNT_MODE
#define PHNT_MODE 1
#endif

#if (PHNT_MODE != PHNT_MODE_KERNEL)
// Some real code here
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants