Scope the base_macros.h warning disables to base.h - #1625
Open
Daniel Jump (DanielJump) wants to merge 1 commit into
Open
Scope the base_macros.h warning disables to base.h#1625Daniel Jump (DanielJump) wants to merge 1 commit into
Daniel Jump (DanielJump) wants to merge 1 commit into
Conversation
base_macros.h disables C5046, C4268, C4499 and C4630 without a matching
#pragma warning(push)/(pop) pair. base.h includes it near the top and never
restores the warning state, so those four warnings stay disabled for the rest
of every translation unit that includes base.h, not just for the C++/WinRT
declarations they were added for.
Consumers silently lose the warnings in their own code:
namespace { struct S { int x; }; }
S f();
int main() { f(); }
That warns C5046 on its own, and stops warning as soon as <winrt/base.h> is
included ahead of it, at both /W4 and /Wall.
Open the scope before the include and close it at the end of base.h. The
disables still cover everything C++/WinRT declares, and the warning state is
handed back to the consumer unchanged. The set of warnings reported from
within the C++/WinRT headers is unaffected.
Copilot started reviewing on behalf of
Ryan Shepherd (DefaultRyan)
September 3, 2026 19:45
View session
There was a problem hiding this comment.
🟢 Approval recommended
The change safely scopes MSVC warning disables to the generated header and is low risk, with only a minor comment-accuracy nit noted.
Pull request overview
This PR fixes warning-state leakage from <winrt/base.h> by scoping the MSVC warning disables originating in base_macros.h so they apply to C++/WinRT’s own declarations but don’t remain disabled for downstream consumer code.
Changes:
- Add a generator-emitted
#pragma warning(push)immediately beforebase_macros.his included in the generatedbase.h. - Ensure a matching
#pragma warning(pop)is emitted at the end of the generatedbase.hvia the existingfinish_withRAII writer pattern. - Document the intended pairing behavior in
strings/base_macros.h.
File summaries
| File | Description |
|---|---|
| strings/base_macros.h | Adds commentary explaining intended warning-disable scoping behavior for MSVC. |
| cppwinrt/file_writers.h | Wraps the base_macros root-include in a push/pop warning scope when generating winrt/base.h. |
| cppwinrt/code_writers.h | Introduces a reusable writer RAII helper that emits #pragma warning(push) and guarantees a matching pop. |
Review details
- Files reviewed: 3/3 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.
Comment on lines
+26
to
+29
| // These disables deliberately apply to the remainder of the file that includes | ||
| // this header, because they cover declarations made throughout C++/WinRT. The | ||
| // including file opens a #pragma warning(push) beforehand and pops it at the | ||
| // end, which keeps them from escaping into consumer code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1624.
base_macros.hdisables C5046, C4268, C4499 and C4630 with no matching#pragma warning(push)/(pop).base.hincludes it near the top and never restores the warning state, so those four warnings stay disabled for the rest of every translation unit that includes<winrt/base.h>- the consumer's own code included.warns C5046 on its own, and goes silent as soon as
<winrt/base.h>is included ahead of it, at both/W4and/Wall.Change
Open the warning scope immediately before the
base_macros.hinclude inwrite_base_hand close it at the end of the file, using the existingfinish_with/wrap_*idiom so the pop cannot be forgotten. The disables still cover every declaration C++/WinRT makes, which is what they were added for; only their escape into consumer code is removed.base_macros.hitself keeps the disables, with a comment recording that the enclosing scope belongs to the including file, so the pairing is discoverable from either side.Validation
Applied the equivalent change to a shipped
winrt/base.hand rebuilt with the Windows SDK headers, MSVC x64,/std:c++20 /permissive- /Wall:warning(pop)with no matchingpush)implements, factories and classic COM reports an identical 166 warnings before and after (C5246 x114, C4365 x21, C4946 x16, C4265 x15), so nothing inside the C++/WinRT headers regressedNot changed
base_macros.his also root-included by the generated component.g.hfiles underWINRT_IMPORT_MODULEand by the global module fragment of each generated.ixx. Those are cppwinrt's own module builds rather than ordinary consumer translation units, and C4499 / C4630 are wanted there, so I left those paths alone. Happy to extend this if you would rather it were uniform.