clang-format issue with macro
By chance, I noticed the following happened, and I'm mentioning it in case it's early enough/worth the effort to fix.
One example: https://github.com/mhammond/pywin32/blob/059b7beb928225e389621802db758c75a7b8c58f/win32/src/win32apimodule.cpp#L133-L136
Ouch - thanks! @konserw, any thoughts?
Sorry, I've missed it. Probably CLang got confused by statement not finished with semicolon. I'm not sure how such case should be dealt with.
Probably CLang got confused by statement not finished with semicolon. I'm not sure how such case should be dealt with.
Correct.
Option 1: Empty statement ; (not a solution that works in all cases, like in braceless conditions)
return NULL;
PyW32_BEGIN_ALLOW_THREADS;
BOOL ok = ::Beep(freq, dur);
PyW32_END_ALLOW_THREADS;
if (!ok) // @pyseeapi Beep
return ReturnAPIError("Beep");
Option 2: Update the macros to be expressions, not statements (requirering manual ; on usage). So it looks like option 1.
Option 3: format-suppression comments
return NULL;
// clang-format off
PyW32_BEGIN_ALLOW_THREADS
BOOL ok = ::Beep(freq, dur);
PyW32_END_ALLOW_THREADS
if (!ok) // clang-format on
// @pyseeapi Beep
return ReturnAPIError("Beep");
Option 4: Add statement macros to configuration: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#statementmacros For example:
StatementMacros: [
PYWIN_MODULE_INIT_RETURN_ERROR
PYWIN_MODULE_INIT_RETURN_SUCCESS
PY_INTERFACE_POSTCALL,
PY_INTERFACE_PRECALL,
PyW32_BEGIN_ALLOW_THREADS,
PyW32_END_ALLOW_THREADS,
]
Would be nice if it autodetected statement macros. Maybe a feature request for https://github.com/llvm/llvm-project/labels/clang-format ?
Option 5: ignore it 🤷
Option 2 or 4 probably look best