From 883484316c33565ee14089ac3be55346a899a9f9 Mon Sep 17 00:00:00 2001 From: Dan Jump Date: Thu, 29 Oct 2026 14:34:09 -0700 Subject: [PATCH 1/3] Fix remaining strict warning defects Use safe ABI casts, explicit enum and Boolean handling, correct aggregate initialization, effective PCH ordering, and remove or annotate unused test helpers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8b45cfea-cc0f-4a1f-8b2a-86c89d063c6c Hostname: DanJump0 --- cppwinrt/cmd_reader.h | 2 +- cppwinrt/code_writers.h | 4 ++++ cppwinrt/type_writers.h | 12 ++++++++++++ strings/base_fast_forward.h | 2 +- strings/base_reference_produce.h | 2 +- test/old_tests/UnitTests/Main.cpp | 2 +- test/old_tests/UnitTests/Parameters.cpp | 2 +- test/test/GetMany.cpp | 8 ++++---- test/test/return_params_abi.cpp | 17 ----------------- test/test_component/Class.cpp | 9 +-------- 10 files changed, 26 insertions(+), 34 deletions(-) diff --git a/cppwinrt/cmd_reader.h b/cppwinrt/cmd_reader.h index e2787b7d4..e45699456 100644 --- a/cppwinrt/cmd_reader.h +++ b/cppwinrt/cmd_reader.h @@ -383,7 +383,7 @@ namespace cppwinrt bool exists(std::string_view const& name) const noexcept { - return m_options.count(name); + return m_options.count(name) != 0; } auto const& values(std::string_view const& name) const noexcept diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index a9aa5bc78..62cffafe9 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -721,6 +721,10 @@ namespace cppwinrt w.write("%.size(), put_abi(%)", param_name, param_name); } break; + case param_category::generic_type: + case param_category::object_type: + case param_category::string_type: + case param_category::struct_type: default: w.write("impl::bind_out(%)", param_name); break; diff --git a/cppwinrt/type_writers.h b/cppwinrt/type_writers.h index 5c2eea23c..44e7de627 100644 --- a/cppwinrt/type_writers.h +++ b/cppwinrt/type_writers.h @@ -271,6 +271,18 @@ namespace cppwinrt case ConstantType::UInt32: write_value(value.ValueUInt32()); break; + case ConstantType::Boolean: + case ConstantType::Char: + case ConstantType::Int8: + case ConstantType::UInt8: + case ConstantType::Int16: + case ConstantType::UInt16: + case ConstantType::Int64: + case ConstantType::UInt64: + case ConstantType::Float32: + case ConstantType::Float64: + case ConstantType::String: + case ConstantType::Class: default: throw std::invalid_argument("Unexpected constant type"); } diff --git a/strings/base_fast_forward.h b/strings/base_fast_forward.h index a73e70a04..65fa8a7d3 100644 --- a/strings/base_fast_forward.h +++ b/strings/base_fast_forward.h @@ -48,7 +48,7 @@ WINRT_EXPORT namespace winrt::impl std::uint8_t Data4[8]; inline bool operator!=(guid const& right) const noexcept { - return std::memcmp(this, &right, sizeof(guid)); + return std::memcmp(this, &right, sizeof(guid)) != 0; } }; diff --git a/strings/base_reference_produce.h b/strings/base_reference_produce.h index db9639cc3..8df1bcb5b 100644 --- a/strings/base_reference_produce.h +++ b/strings/base_reference_produce.h @@ -134,7 +134,7 @@ WINRT_EXPORT namespace winrt::impl if (is_guid_of(id)) { - auto unknown = reinterpret_cast(to_abi(derived())); + auto unknown = abi_cast(to_abi(derived())); unknown->AddRef(); *object = unknown; return error_ok; diff --git a/test/old_tests/UnitTests/Main.cpp b/test/old_tests/UnitTests/Main.cpp index 60b1eb6d8..c8c8e22ca 100644 --- a/test/old_tests/UnitTests/Main.cpp +++ b/test/old_tests/UnitTests/Main.cpp @@ -1,5 +1,5 @@ -#include #include "pch.h" +#include #define CATCH_CONFIG_RUNNER diff --git a/test/old_tests/UnitTests/Parameters.cpp b/test/old_tests/UnitTests/Parameters.cpp index 411e3eb71..8945763eb 100644 --- a/test/old_tests/UnitTests/Parameters.cpp +++ b/test/old_tests/UnitTests/Parameters.cpp @@ -44,7 +44,7 @@ TEST_CASE("Parameters") std::array view; params.CopyInt32Array(view); - REQUIRE(view == std::array{1, 2, 3}); + REQUIRE(view == std::array{{ 1, 2, 3 }}); } { diff --git a/test/test/GetMany.cpp b/test/test/GetMany.cpp index 292912046..44a691d01 100644 --- a/test/test/GetMany.cpp +++ b/test/test/GetMany.cpp @@ -100,12 +100,12 @@ TEST_CASE("GetMany") REQUIRE(buffer[0] == 1); REQUIRE(buffer[1] == 2); REQUIRE(buffer[2] == 3); - buffer = { 0xCC, 0xCC, 0xCC }; + buffer = {{ 0xCC, 0xCC, 0xCC }}; REQUIRE(1 == pos.GetMany(buffer)); REQUIRE(buffer[0] == 4); REQUIRE(buffer[1] == 0xCC); REQUIRE(buffer[2] == 0xCC); - buffer = { 0xCC, 0xCC, 0xCC }; + buffer = {{ 0xCC, 0xCC, 0xCC }}; REQUIRE(0 == pos.GetMany(buffer)); REQUIRE(buffer[0] == 0xCC); REQUIRE(buffer[1] == 0xCC); @@ -278,12 +278,12 @@ TEST_CASE("GetMany") REQUIRE(buffer[0] == 1); REQUIRE(buffer[1] == 2); REQUIRE(buffer[2] == 3); - buffer = { 0xCC, 0xCC, 0xCC }; + buffer = {{ 0xCC, 0xCC, 0xCC }}; REQUIRE(2 == v.GetMany(buffer)); REQUIRE(buffer[0] == 4); REQUIRE(buffer[1] == 5); REQUIRE(buffer[2] == 0xCC); - buffer = { 0xCC, 0xCC, 0xCC }; + buffer = {{ 0xCC, 0xCC, 0xCC }}; REQUIRE(0 == v.GetMany(buffer)); REQUIRE(buffer[0] == 0xCC); REQUIRE(buffer[1] == 0xCC); diff --git a/test/test/return_params_abi.cpp b/test/test/return_params_abi.cpp index 5e7c11cd3..36c5cfc6c 100644 --- a/test/test/return_params_abi.cpp +++ b/test/test/return_params_abi.cpp @@ -10,23 +10,6 @@ namespace winrt using namespace winrt; -namespace -{ -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-function" -#endif - hstring to_hstring(::IInspectable* raw) - { - winrt::IInspectable object; - copy_from_abi(object, raw); - return object.as().ToString(); - } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif -} - TEST_CASE("return_params_abi") { Class object; diff --git a/test/test_component/Class.cpp b/test/test_component/Class.cpp index 3f68d96c3..ac5565229 100644 --- a/test/test_component/Class.cpp +++ b/test/test_component/Class.cpp @@ -519,14 +519,7 @@ namespace winrt::test_component::implementation namespace { -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-function" -#endif - void ValidateStaticEventAutoRevoke() { + [[maybe_unused]] void ValidateStaticEventAutoRevoke() { auto x = winrt::test_component::Simple::StaticEvent(winrt::auto_revoke, [](auto&&, auto&&) {}); } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif } \ No newline at end of file From a2170e3fdb096daf97638c061bf9a8189385a654 Mon Sep 17 00:00:00 2001 From: Dan Jump Date: Fri, 30 Oct 2026 06:47:38 -0700 Subject: [PATCH 2/3] Simplify const ABI pointer conversion Preserve constness through abi_cast and remove it only from the final ABI pointer, avoiding redundant implementation and base-class casts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8b45cfea-cc0f-4a1f-8b2a-86c89d063c6c Hostname: DanJump0 --- strings/base_implements.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/base_implements.h b/strings/base_implements.h index 7d556513d..f1ea78cd4 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -275,13 +275,13 @@ WINRT_EXPORT namespace winrt template impl::abi_t* to_abi(impl::producer const* from) noexcept { - return impl::abi_cast>(const_cast*>(from)); + return const_cast*>(impl::abi_cast const>(from)); } template impl::abi_t* to_abi(impl::producer_convert const* from) noexcept { - return impl::abi_cast>(const_cast>*>(static_cast> const*>(from))); + return const_cast*>(impl::abi_cast const>(from)); } } From 4c9a5f47fffaa5900db9b0acc174fe37ff23f019 Mon Sep 17 00:00:00 2001 From: Dan Jump Date: Fri, 30 Oct 2026 07:21:25 -0700 Subject: [PATCH 3/3] Simplify weak reference flag detection Interpret the encoded high bit through intptr_t and test for a negative value instead of rebuilding and masking a pointer-sized flag. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8b45cfea-cc0f-4a1f-8b2a-86c89d063c6c Hostname: DanJump0 --- strings/base_implements.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/strings/base_implements.h b/strings/base_implements.h index f1ea78cd4..c7f5da704 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -1281,8 +1281,7 @@ WINRT_EXPORT namespace winrt::impl static bool is_weak_ref(std::uintptr_t const value) noexcept { static_assert(is_weak_ref_source::value, "Weak references are not supported because no_weak_ref was specified."); - constexpr std::uintptr_t pointer_flag = static_cast(1) << ((sizeof(std::uintptr_t) * 8) - 1); - return (value & pointer_flag) != 0; + return static_cast(value) < 0; } static weak_ref_t* decode_weak_ref(std::uintptr_t const value) noexcept