Skip to content

Error handling helpers internals

Raymond Chen edited this page Apr 14, 2021 · 2 revisions

This page describes implementation details of the WIL error handling helpers. Apps should not rely on these details, because they are subject to change. The details are documented here to assist with debugging and to assist people who are implementing WIL itself.

Return macros

The return macros generally expand to

__WI_SUPPRESS_4127_S
do {
    ...
    if (some_condition(...)) {
        __RETURN_SOMETHING(...);
    }
} __WI_SUPPRESS_4127_E while ((void)0, 0)
  • The do { ... } while (0) pattern is a standard pattern for avoiding issues with statement-like macros.
  • The condition in the while() is while ((void)0, 0) to attempt to avoid "conditional expression is constant" warnings. The comma operator prevents the controlling expression from being a constant expression (per the C++ language rules) and therefore avoids the compiler warning.
  • __WI_SUPPRESS_4127_S temporarily suppresses warning 4127: Conditional expression is constant.
  • __WI_SUPPRESS_4127_E restores the previous state of warning 4127.

The body of the do loop is performed with warning 4127 suppressed because the some_condition(...) may, after compiler optimization, turn into a constant that is always true or always false.

  • The __RETURN_SOMETHING(...) is itself another macro that performs logging before eventually executing a return (something).