Add missing headers and std qualification, use std::numeric_limits in…#1546
Add missing headers and std qualification, use std::numeric_limits in…#1546DefaultRyan merged 4 commits intomicrosoft:masterfrom
Conversation
…stead of macros, and use std::memcpy/std::swprintf instead of the non-standard memcpy_s/swprintf_s
There was a problem hiding this comment.
Pull request overview
This PR modernizes and standardizes the C++/WinRT embedded runtime headers and the cppwinrt tool sources by consistently qualifying fixed-width integer types with std::, replacing macro-based limits with std::numeric_limits, and preferring standard C++ library functions (std::memcpy, std::swprintf, etc.) over non-standard or platform-specific variants.
Changes:
- Standardize integer and size types across headers (
std::uint32_t,std::size_t, etc.) and update related APIs/signatures. - Replace macro-based bounds checks with
std::numeric_limitsand move C-library calls intostd::(std::memcpy,std::memset,std::wcslen,std::iswspace,std::abort, etc.). - Add/update standard header includes to support the above changes.
Reviewed changes
Copilot reviewed 43 out of 43 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| strings/base_xaml_typename.h | Switch XAML typename traits to std::int*_t/std::uint*_t. |
| strings/base_xaml_component_connector_winui.h | Use std::int32_t for connector IDs. |
| strings/base_xaml_component_connector.h | Use std::int32_t for connector IDs. |
| strings/base_windows.h | Standardize counters/alloc signatures to std::* types. |
| strings/base_version.h | Use std::size_t consistently for template params/loops. |
| strings/base_types.h | Standardize ABI/helper types and use std::memcmp. |
| strings/base_string_operators.h | Replace memcpy_s with std::memcpy. |
| strings/base_string_input.h | Use std::wcslen, std::size_t, and std::numeric_limits. |
| strings/base_string.h | Standardize integer types; use std::memcpy, std::abort, std::swprintf, etc. |
| strings/base_std_hash.h | Standardize sizes/bytes to std::size_t / std::uint8_t. |
| strings/base_security.h | Standardize Win32 error type to std::uint32_t. |
| strings/base_reference_produce.h | Standardize property/reference traits to std::* integer types. |
| strings/base_natvis.h | Standardize debug helper layout integer types. |
| strings/base_marshaler.h | Standardize COM ABI method signatures to std::* integer types. |
| strings/base_lock.h | Standardize timeout casts to std::uint32_t. |
| strings/base_iterator.h | Use std::ptrdiff_t and std::uint32_t for iterator internals. |
| strings/base_includes.h | Add standard headers to support new std:: usages. |
| strings/base_implements.h | Standardize COM ABI signatures and use std::memset. |
| strings/base_identity.h | Standardize template sizes/arrays/crypto helpers to std::* types. |
| strings/base_fast_forward.h | Standardize fast-forward ABI types and internal helpers. |
| strings/base_extern.h | Standardize exported handler signatures and Win32 ABI declarations. |
| strings/base_events.h | Standardize event token and collection internals to std::* types. |
| strings/base_error.h | Standardize error helpers to std::* types and std::abort/std::iswspace. |
| strings/base_delegate.h | Standardize delegate ABI signatures and ref-count types. |
| strings/base_deferral.h | Standardize outstanding deferral counter type. |
| strings/base_coroutine_threadpool.h | Standardize coroutine threadpool ABI types and counters. |
| strings/base_coroutine_foundation.h | Standardize timeout/failure/result types to std::* integers. |
| strings/base_com_ptr.h | Standardize capture helpers to return std::int32_t. |
| strings/base_collections_vector.h | Standardize vector ABI indices/sizes to std::uint32_t. |
| strings/base_collections_map.h | Standardize tuple helpers to std::size_t. |
| strings/base_collections_base.h | Standardize collection ABI sizes/indices to std::uint32_t. |
| strings/base_collections.h | Standardize versioning to std::uint32_t. |
| strings/base_chrono.h | Standardize time representations to std::int64_t/std::uint64_t. |
| strings/base_array.h | Standardize array_view/com_array sizes to std::uint32_t and related template params. |
| strings/base_agile_ref.h | Standardize agile ref lock counters to std::uint32_t. |
| strings/base_activation.h | Standardize interlocked helpers and COM activation types to std::* integers. |
| strings/base_abi.h | Standardize ABI interface method signatures to std::* integers. |
| cppwinrt/type_writers.h | Emit std::* integer types for generated type spellings. |
| cppwinrt/text_writer.h | Move stdio calls to std::printf/std::fprintf/std::snprintf; standardize sizes. |
| cppwinrt/helpers.h | Standardize loop counters/contract versioning types to std::* integers. |
| cppwinrt/component_writers.h | Standardize emitted signatures and use std::toupper. |
| cppwinrt/code_writers.h | Standardize GUID emission types and generated ABI method signatures. |
| cppwinrt/cmd_reader.h | Standardize option bounds/types and use std::tolower/std::numeric_limits. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR standardizes the project’s C++ runtime usage by adding missing standard headers, fully qualifying fixed-width/size types with std::, replacing macro-based limits with std::numeric_limits, and preferring standard library functions (e.g., std::memcpy, std::swprintf) over non-standard or platform-specific variants.
Changes:
- Replace unqualified
int32_t/uint32_t/...,size_t,ptrdiff_t, and C library calls withstd::int32_t/...,std::size_t,std::ptrdiff_t, andstd::-qualified functions. - Add missing standard headers to ensure the new qualifications compile reliably (
<cstdint>,<cstdlib>,<cwchar>,<cwctype>,<limits>,<cstdio>,<cctype>). - Use
std::numeric_limitsinstead of macros likeUINT_MAX/INT_MAXfor range checks.
Reviewed changes
Copilot reviewed 43 out of 43 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| strings/base_xaml_typename.h | Switch XAML typename specializations to std::int*_t/std::uint*_t. |
| strings/base_xaml_component_connector_winui.h | Use std::int32_t for XAML connection IDs. |
| strings/base_xaml_component_connector.h | Use std::int32_t for XAML connection IDs. |
| strings/base_windows.h | Qualify integer sizes and operator new parameter with std::. |
| strings/base_version.h | Qualify template and loop size types with std::size_t. |
| strings/base_types.h | Qualify fixed-width types and std::memcmp usage. |
| strings/base_string_operators.h | Replace memcpy_s with std::memcpy and qualify size type. |
| strings/base_string_input.h | Use std::wcslen, std::size_t, and std::numeric_limits for bounds checks. |
| strings/base_string.h | Qualify fixed-width types; use std::abort, std::memcpy, std::wcslen, std::numeric_limits. |
| strings/base_std_hash.h | Qualify size_t/byte types to std::size_t/std::uint8_t. |
| strings/base_security.h | Qualify Win32 error type to std::uint32_t. |
| strings/base_reference_produce.h | Qualify scalar and array reference types to std::int*_t/std::uint*_t. |
| strings/base_natvis.h | Qualify fixed-width and pointer-sized types; update accessor typedef. |
| strings/base_marshaler.h | Qualify COM ABI method return/param types with std::. |
| strings/base_lock.h | Qualify milliseconds cast to std::uint32_t. |
| strings/base_iterator.h | Use std::ptrdiff_t and std::uint32_t for iterator internals. |
| strings/base_includes.h | Add missing standard headers required by new std:: usage. |
| strings/base_implements.h | Qualify COM ABI signatures; use std::memset and std::uintptr_t. |
| strings/base_identity.h | Qualify size_t/byte arrays and related helpers with std::. |
| strings/base_fast_forward.h | Add headers and qualify ABI types; update memcmp usage. |
| strings/base_extern.h | Qualify extern handler function pointer signatures and Win32 ABI declarations. |
| strings/base_events.h | Qualify event token and sizes; adjust HRESULT constant casts. |
| strings/base_error.h | Use std::iswspace, qualify types, and use std::abort. |
| strings/base_delegate.h | Qualify COM ABI signatures and reference counting types. |
| strings/base_deferral.h | Qualify outstanding deferral counter type. |
| strings/base_coroutine_threadpool.h | Qualify apartment/TP types and result storage types. |
| strings/base_coroutine_foundation.h | Qualify timeouts and reference count types. |
| strings/base_com_ptr.h | Qualify HRESULT return types for capture helpers. |
| strings/base_collections_vector.h | Qualify indices/sizes to std::uint32_t and casts. |
| strings/base_collections_map.h | Qualify tuple traits indices/sizes to std::size_t. |
| strings/base_collections_base.h | Qualify collection sizes/indices and internal size calculations. |
| strings/base_collections.h | Qualify versioning snapshot and atomic version type. |
| strings/base_chrono.h | Qualify file_time storage and clock rep types. |
| strings/base_array.h | Qualify array view/com_array sizes and std::memset usage. |
| strings/base_agile_ref.h | Qualify trivial lock counter operators’ return type. |
| strings/base_activation.h | Qualify interlocked read types and context/size types; qualify apartment init args. |
| strings/base_abi.h | Qualify all ABI interface method signatures to std::int32_t/std::uint32_t. |
| cppwinrt/type_writers.h | Emit std::int64_t and std::(u)int*_t in generated code. |
| cppwinrt/text_writer.h | Add <cstdio> and use std::printf/std::snprintf/std::fprintf; qualify sizes/indent types. |
| cppwinrt/helpers.h | Qualify index/version types and enum value extraction to std::int32_t. |
| cppwinrt/component_writers.h | Qualify return/index types and use std::toupper in transforms. |
| cppwinrt/code_writers.h | Qualify GUID field extraction types; qualify difference_type to std::ptrdiff_t; qualify generated ABI return types. |
| cppwinrt/cmd_reader.h | Add <cctype>; qualify sizes/limits and use std::tolower; use std::numeric_limits for option bounds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ts<T>::max from the max macro
DefaultRyan
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks for this update.
…stead of macros, and use std::memcpy/std::swprintf instead of the non-standard memcpy_s/swprintf_s
memcpy_s and swprintf_s are not in the C++ standard, therefore they are not exported by std or std.compat. Other declarations are either exported by std.compat or become available due to the global module fragment (this is unstable unless all required headers are explicitly included). Ideally, only the module std should be used.