PHNT #if directives causes "token is not a valid binary operator in a preprocessor subexpression"
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
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.
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.
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
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