Harden Windows macros against dangling-else ambiguity - #41513
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
The new do { ... } while (false) macro expansions are missing the trailing semicolons, making them inconsistent with other macros in the header and potentially breaking existing call sites that omitted ; previously.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens Windows-side user warning / user-error helper macros in ExecutionContext.h by wrapping them in do { ... } while (false) so they behave as a single statement and avoid dangling-else misassociation in if/else constructs.
Changes:
- Wrap
THROW_HR_WITH_USER_ERROR_IFin ado { ... } while (false)guard. - Wrap
EMIT_USER_WARNINGin ado { ... } while (false)guard.
File summaries
| File | Description |
|---|---|
| src/windows/common/ExecutionContext.h | Wrapes the two macros in do { ... } while (false) to prevent dangling-else ambiguity in caller code. |
Review details
Suppressed comments (1)
src/windows/common/ExecutionContext.h:47
- This
do { ... } while (false)wrapper is missing the trailing semicolon. Adding it makes the macro a complete statement (matching other macros in this header) and avoids forcing all call sites to include a trailing;where the previousif (...) { ... }form did not require one.
#define EMIT_USER_WARNING(Warning) \
do \
{ \
if (::wsl::windows::common::ExecutionContext* context = ::wsl::windows::common::ExecutionContext::Current(); context != nullptr) \
{ \
context->EmitUserWarning(Warning); \
} \
} while (false)
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟢 Approval recommended
The change is a small, well-scoped macro hardening that preserves behavior while eliminating a confirmed control-flow ambiguity.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Ben Hillis (benhillis)
left a comment
There was a problem hiding this comment.
Change looks good to me, thank you for the contribution!
Summary of the Pull Request
Hardens
EMIT_USER_WARNINGandTHROW_HR_WITH_USER_ERROR_IFinsrc/windows/common/ExecutionContext.hby wrapping them indo { ... } while (false)statement wrappers. This is the Windows counterpart to the Linux fix in #41504.PR Checklist
<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
Detailed Description of the Pull Request / Additional comments
Both
EMIT_USER_WARNINGandTHROW_HR_WITH_USER_ERROR_IFwere defined as bareifstatements, leaving Windows callers vulnerable to dangling-else misassociation when the macros are used without braces:This change wraps both macros in do { ... } while (false) so they always expand to a single statement. This brings the Windows header into parity with the already-hardened Linux definition from #41504 and prevents the outer else from binding to the inner if generated by the macro.
Validation Steps Performed