Repository navigation
Fix integral conversion and brace elision warnings - #1621
Ryan Shepherd (DefaultRyan) merged 2 commits into
Conversation
6fb1dbd to
035a9c4
Compare
Consumers that build at high warning levels must currently wrap every C++/WinRT include in warning pragmas. These sites account for MSVC C5246 (brace elision), C4365 (signed/unsigned conversion), C4826 (sign-extended pointer cast) and C4946 (reinterpret_cast between related classes) under /Wall on x64 and x86. std::array aggregate initialization needs two brace levels. Iterator arithmetic from uint32_t needs an explicit ptrdiff_t cast on 32-bit. to_hstring widened char to wchar_t via std::copy, which a caller cannot silence because the assignment happens inside <xutility>. The ABI conversions cannot simply use static_cast: a WinRT interface derives from unknown_abi, but a classic COM interface derives from ::IUnknown and is layout compatible but unrelated. impl::abi_cast picks static_cast when a conversion exists and falls back to reinterpret_cast otherwise, so C4946 is avoided wherever the types are actually related. The same applies in reverse for to_abi, since producer derives from the interface for classic COM but holds its vtable by value for WinRT.
035a9c4 to
8d9153e
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The warning fixes are behavior-preserving, appropriately scoped, and covered by existing collection, string, event, weak-reference, and COM tests.
0 open findings
What changed in this PR
Eliminates MSVC /Wall warnings in foundational C++/WinRT headers without changing intended behavior or public APIs.
Changes:
- Adds explicit integral and iterator-offset conversions.
- Corrects
std::arrayaggregate initialization. - Introduces ABI-aware casting and explicit weak-reference/pointer bit handling.
| File | Description |
|---|---|
strings/base_types.h |
Makes narrowing conversions explicit. |
strings/base_string.h |
Fixes reference-count, string-size, and character-widening warnings. |
strings/base_implements.h |
Adds ABI casting and explicit weak-reference detection. |
strings/base_identity.h |
Corrects array braces and integral conversions. |
strings/base_events.h |
Converts encoded pointers without sign-extension warnings. |
strings/base_error.h |
Explicitly converts HRESULT values for FormatMessageW. |
strings/base_collections_vector.h |
Uses iterator-compatible offsets. |
strings/base_collections_base.h |
Uses ptrdiff_t for iterator arithmetic. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Preserve the warning fixes while retaining the newer resize_and_overwrite string conversion path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8b45cfea-cc0f-4a1f-8b2a-86c89d063c6c Hostname: DanJump0
|
AI-generated Merged current master into this branch and resolved the base_string.h conflict, preserving both the warning fix and the newer resize_and_overwrite path. The branch is mergeable and CI is rerunning. The previous approval was dismissed by the head update. Ryan Shepherd (@DefaultRyan), please re-review when convenient. |
9bb8a57
into
microsoft:master
|
Thanks Daniel Jump (@DanielJump) . Approved. |
These sites produce MSVC warnings under
/Wallon both x64 and x86, which forces consumers building at high warning levels to wrap every C++/WinRT include in#pragma warningblocks.base_identity.hstd::arrayaggregate init needs two brace levelsbase_collections_base.h,base_collections_vector.h,base_string.h,base_error.h,base_types.huint32_t->ptrdiff_titerator arithmetic on 32-bitbase_events.hreinterpret_castof a pointer toint64_tsign-extendsbase_implements.hreinterpret_castbetween related classes; every abi type derives fromunknown_abi, sostatic_castis correctTwo are worth calling out:
to_hstringusedstd::copyto widenchartowchar_t. The assignment happens inside<xutility>, so a caller cannot silence it;std::transformwith an explicit cast can.to_charsonly writes ASCII there, so the cast is exact. Minimal repro:is_weak_reftookintptr_tand testedvalue < 0while every caller holds auintptr_t. It now takesuintptr_tand tests the high bit explicitly.No generated files change, and no public signatures change.
Validated on a translation unit exercising
implements<>, delegates, events, all collection flavours, coroutines,agile_ref,weak_ref, boxing and error handling.Part of #1620.