pywin32 icon indicating copy to clipboard operation
pywin32 copied to clipboard

clang-format issue with macro

Open nczeczulin opened this issue 6 years ago • 3 comments

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

nczeczulin avatar Sep 23 '19 05:09 nczeczulin

Ouch - thanks! @konserw, any thoughts?

mhammond avatar Sep 23 '19 05:09 mhammond

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.

konserw avatar Sep 23 '19 11:09 konserw

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

Avasam avatar Oct 15 '24 05:10 Avasam