From 3e79df62a7dde97848fc0fcac8ddcf32a7eca670 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Fri, 7 Oct 2022 14:31:02 -0400 Subject: [PATCH 1/5] Fix Clang-15 warnings Mostly dealing with initialization and codestyle. --- cppwinrt/cmd_reader.h | 7 +++---- cppwinrt/code_writers.h | 15 ++++++--------- cppwinrt/component_writers.h | 10 +++++----- cppwinrt/helpers.h | 2 +- cppwinrt/text_writer.h | 6 +++--- natvis/cppwinrt_visualizer.cpp | 4 ++-- natvis/object_visualizer.cpp | 2 +- prebuild/main.cpp | 2 +- strings/base_collections_input_vector.h | 2 +- strings/base_coroutine_foundation.h | 2 +- strings/base_implements.h | 6 +++--- test/old_tests/UnitTests/handle.cpp | 2 +- 12 files changed, 28 insertions(+), 32 deletions(-) diff --git a/cppwinrt/cmd_reader.h b/cppwinrt/cmd_reader.h index c86cfdcc6..9886b79cf 100644 --- a/cppwinrt/cmd_reader.h +++ b/cppwinrt/cmd_reader.h @@ -195,11 +195,10 @@ namespace cppwinrt inline std::string get_module_path() { std::string path(100, '?'); - DWORD actual_size{}; - while (true) + for (;;) { - actual_size = GetModuleFileNameA(nullptr, path.data(), 1 + static_cast(path.size())); + DWORD actual_size = GetModuleFileNameA(nullptr, path.data(), 1 + static_cast(path.size())); if (actual_size < 1 + path.size()) { @@ -234,7 +233,7 @@ namespace cppwinrt auto key = open_sdk(); uint32_t index{}; - std::array subkey; + std::array subkey{}; std::array version_parts{}; std::string result; diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index 748996b1a..c9f99c9ea 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -417,7 +417,7 @@ namespace cppwinrt static void write_generic_names(writer& w, std::pair const& params) { - bool first{ true }; + bool first = true; for (auto&& param : params) { @@ -2011,7 +2011,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable w.write_each(info.type.MethodList(), name); } - }; + } } static void write_class_override_implements(writer& w, get_interfaces_t const& interfaces) @@ -2035,21 +2035,18 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable static void write_class_override_requires(writer& w, get_interfaces_t const& interfaces) { - bool found{}; - for (auto&& [name, info] : interfaces) { if (!info.overridable) { w.write(", %", name); - found = true; } } } static void write_class_override_defaults(writer& w, get_interfaces_t const& interfaces) { - bool first{ true }; + bool first = true; for (auto&& [name, info] : interfaces) { @@ -2769,7 +2766,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable static void write_class_requires(writer& w, TypeDef const& type) { - bool first{ true }; + bool first = true; for (auto&& [interface_name, info] : get_interfaces(w, type)) { @@ -2793,7 +2790,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable static void write_fast_class_requires(writer& w, TypeDef const& type) { - bool first{ true }; + bool first = true; for (auto&& [interface_name, info] : get_interfaces(w, type)) { @@ -2817,7 +2814,7 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable static void write_class_base(writer& w, TypeDef const& type) { - bool first{ true }; + bool first = true; for (auto&& base : get_bases(type)) { diff --git a/cppwinrt/component_writers.h b/cppwinrt/component_writers.h index acd2b871c..aaa89b91d 100644 --- a/cppwinrt/component_writers.h +++ b/cppwinrt/component_writers.h @@ -27,7 +27,7 @@ namespace cppwinrt } } - bool first{ true }; + bool first = true; for (auto&& name : interfaces) { @@ -45,7 +45,7 @@ namespace cppwinrt static void write_component_class_base(writer& w, TypeDef const& type) { - bool first{ true }; + bool first = true; for (auto&& base : get_bases(type)) { @@ -289,7 +289,7 @@ catch (...) { return winrt::to_hresult(); } bind(signature)); } - void write_component_static_forwarder(writer& w, MethodDef const& method) + inline void write_component_static_forwarder(writer& w, MethodDef const& method) { auto format = R"( auto %(%) { @@ -643,8 +643,8 @@ catch (...) { return winrt::to_hresult(); } { if (!info.base && info.is_default) { - auto methods = info.type.MethodList(); - offset += methods.second - methods.first; + auto [fst, snd] = info.type.MethodList(); + offset += snd - fst; break; } } diff --git a/cppwinrt/helpers.h b/cppwinrt/helpers.h index b2d783d61..a3b865b6e 100644 --- a/cppwinrt/helpers.h +++ b/cppwinrt/helpers.h @@ -127,7 +127,7 @@ namespace cppwinrt struct separator { writer& w; - bool first{ true }; + bool first = true; void operator()() { diff --git a/cppwinrt/text_writer.h b/cppwinrt/text_writer.h index bde87806e..4631196b7 100644 --- a/cppwinrt/text_writer.h +++ b/cppwinrt/text_writer.h @@ -341,7 +341,7 @@ namespace cppwinrt std::string_view::size_type current_pos{ 0 }; auto on_new_line = writer_base::back() == '\n'; - while (true) + for (;;) { const auto pos = value.find('\n', current_pos); @@ -461,7 +461,7 @@ namespace cppwinrt { return [&](auto& writer) { - bool first{ true }; + bool first = true; for (auto&& item : list) { @@ -484,7 +484,7 @@ namespace cppwinrt { return [&](auto& writer) { - bool first{ true }; + bool first = true; for (auto&& item : list) { diff --git a/natvis/cppwinrt_visualizer.cpp b/natvis/cppwinrt_visualizer.cpp index b44be1268..29b9e6306 100644 --- a/natvis/cppwinrt_visualizer.cpp +++ b/natvis/cppwinrt_visualizer.cpp @@ -93,7 +93,7 @@ void LoadMetadata(DkmProcess* process, WCHAR const* processPath, std::string_vie { auto winmd_path = path{ processPath }; auto probe_file = std::string{ typeName }; - do + for (;;) { winmd_path.replace_filename(probe_file + ".winmd"); MetadataDiagnostic(process, L"Looking for ", winmd_path); @@ -115,7 +115,7 @@ void LoadMetadata(DkmProcess* process, WCHAR const* processPath, std::string_vie break; } probe_file = probe_file.substr(0, pos); - } while (true); + } } TypeDef FindType(DkmProcess* process, std::string_view const& typeName) diff --git a/natvis/object_visualizer.cpp b/natvis/object_visualizer.cpp index 8bcb86877..5308c33fc 100644 --- a/natvis/object_visualizer.cpp +++ b/natvis/object_visualizer.cpp @@ -573,7 +573,7 @@ HRESULT object_visualizer::CreateEvaluationResult(_Deref_out_ DkmEvaluationResul auto address = pPointerValueHome->Address(); com_ptr pValue; - DkmEvaluationResultFlags_t evalResultFlags = DkmEvaluationResultFlags::ReadOnly | DkmEvaluationResultFlags::Expandable;; + DkmEvaluationResultFlags_t evalResultFlags = DkmEvaluationResultFlags::ReadOnly | DkmEvaluationResultFlags::Expandable; if (requires_refresh(address, m_pVisualizedExpression->InspectionContext()->EvaluationFlags())) { IF_FAIL_RET(DkmString::Create(L"", pValue.put())); diff --git a/prebuild/main.cpp b/prebuild/main.cpp index d446c02d4..52a750776 100644 --- a/prebuild/main.cpp +++ b/prebuild/main.cpp @@ -49,7 +49,7 @@ namespace cppwinrt::strings { std::string_view remainder = view; - while (remainder.size()) + while (!remainder.empty()) { auto const size = std::min(size_t{ 16'000 }, remainder.size()); auto const chunk = remainder.substr(0, size); diff --git a/strings/base_collections_input_vector.h b/strings/base_collections_input_vector.h index 2482db968..b5b76de38 100644 --- a/strings/base_collections_input_vector.h +++ b/strings/base_collections_input_vector.h @@ -88,7 +88,7 @@ WINRT_EXPORT namespace winrt::param private: interface_type m_interface; - bool m_owned{ true }; + bool m_owned = true; }; template diff --git a/strings/base_coroutine_foundation.h b/strings/base_coroutine_foundation.h index 3c309256c..71dbb0043 100644 --- a/strings/base_coroutine_foundation.h +++ b/strings/base_coroutine_foundation.h @@ -149,7 +149,7 @@ namespace winrt::impl Async const& async; Windows::Foundation::AsyncStatus status = Windows::Foundation::AsyncStatus::Started; int32_t failure = 0; - std::atomic suspending{ true }; + std::atomic suspending = true; void enable_cancellation(cancellable_promise* promise) { diff --git a/strings/base_implements.h b/strings/base_implements.h index 53826d6b6..00019e7a5 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -692,7 +692,7 @@ namespace winrt::impl { uint32_t target = m_strong.load(std::memory_order_relaxed); - while (true) + for (;;) { if (target == 0) { @@ -924,7 +924,7 @@ namespace winrt::impl { uintptr_t count_or_pointer = m_references.load(std::memory_order_relaxed); - while (true) + for (;;) { if (is_weak_ref(count_or_pointer)) { @@ -1048,7 +1048,7 @@ namespace winrt::impl { uintptr_t count_or_pointer = m_references.load(std::memory_order_relaxed); - while (true) + for (;;) { if (is_weak_ref(count_or_pointer)) { diff --git a/test/old_tests/UnitTests/handle.cpp b/test/old_tests/UnitTests/handle.cpp index 1b06aac87..f2e69a54d 100644 --- a/test/old_tests/UnitTests/handle.cpp +++ b/test/old_tests/UnitTests/handle.cpp @@ -76,7 +76,7 @@ static void test_put(HANDLE * value) REQUIRE(value != nullptr); REQUIRE(*value == nullptr); - *value = CreateEvent(nullptr, true, true, nullptr);; + *value = CreateEvent(nullptr, true, true, nullptr); } TEST_CASE("handle, put") From 5a2b497b89609cc62ecf8ccbf4f13d41eaea4599 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:22:35 -0400 Subject: [PATCH 2/5] Update cppwinrt/component_writers.h Co-authored-by: Kenny Kerr --- cppwinrt/component_writers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cppwinrt/component_writers.h b/cppwinrt/component_writers.h index aaa89b91d..30d066cee 100644 --- a/cppwinrt/component_writers.h +++ b/cppwinrt/component_writers.h @@ -289,7 +289,7 @@ catch (...) { return winrt::to_hresult(); } bind(signature)); } - inline void write_component_static_forwarder(writer& w, MethodDef const& method) + static void write_component_static_forwarder(writer& w, MethodDef const& method) { auto format = R"( auto %(%) { From d99e2145530c4f0667fe75b10b5ab2783b3377fa Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:22:40 -0400 Subject: [PATCH 3/5] Update cppwinrt/component_writers.h Co-authored-by: Kenny Kerr --- cppwinrt/component_writers.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cppwinrt/component_writers.h b/cppwinrt/component_writers.h index 30d066cee..fcfeddac0 100644 --- a/cppwinrt/component_writers.h +++ b/cppwinrt/component_writers.h @@ -643,8 +643,8 @@ catch (...) { return winrt::to_hresult(); } { if (!info.base && info.is_default) { - auto [fst, snd] = info.type.MethodList(); - offset += snd - fst; + auto [first, second] = info.type.MethodList(); + offset += second - first; break; } } From a34a5325aca0dd1b070a21011babab995436ae32 Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:24:22 -0400 Subject: [PATCH 4/5] use while (true) instead of for (;;) --- cppwinrt/cmd_reader.h | 6 +++--- cppwinrt/text_writer.h | 2 +- natvis/cppwinrt_visualizer.cpp | 2 +- strings/base_implements.h | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cppwinrt/cmd_reader.h b/cppwinrt/cmd_reader.h index 9886b79cf..4c8d2813e 100644 --- a/cppwinrt/cmd_reader.h +++ b/cppwinrt/cmd_reader.h @@ -196,7 +196,7 @@ namespace cppwinrt { std::string path(100, '?'); - for (;;) + while (true) { DWORD actual_size = GetModuleFileNameA(nullptr, path.data(), 1 + static_cast(path.size())); @@ -602,7 +602,7 @@ namespace cppwinrt first_arg = true; *argument_count = 0; - for (;;) + while (true) { if (*p) { @@ -620,7 +620,7 @@ namespace cppwinrt if (*p == '\0') break; - for (;;) + while (true) { copy_character = true; diff --git a/cppwinrt/text_writer.h b/cppwinrt/text_writer.h index 4631196b7..50e6e6b15 100644 --- a/cppwinrt/text_writer.h +++ b/cppwinrt/text_writer.h @@ -341,7 +341,7 @@ namespace cppwinrt std::string_view::size_type current_pos{ 0 }; auto on_new_line = writer_base::back() == '\n'; - for (;;) + while (true) { const auto pos = value.find('\n', current_pos); diff --git a/natvis/cppwinrt_visualizer.cpp b/natvis/cppwinrt_visualizer.cpp index 29b9e6306..f6affd566 100644 --- a/natvis/cppwinrt_visualizer.cpp +++ b/natvis/cppwinrt_visualizer.cpp @@ -93,7 +93,7 @@ void LoadMetadata(DkmProcess* process, WCHAR const* processPath, std::string_vie { auto winmd_path = path{ processPath }; auto probe_file = std::string{ typeName }; - for (;;) + while (true) { winmd_path.replace_filename(probe_file + ".winmd"); MetadataDiagnostic(process, L"Looking for ", winmd_path); diff --git a/strings/base_implements.h b/strings/base_implements.h index 00019e7a5..8016bef28 100644 --- a/strings/base_implements.h +++ b/strings/base_implements.h @@ -692,7 +692,7 @@ namespace winrt::impl { uint32_t target = m_strong.load(std::memory_order_relaxed); - for (;;) + while (true) { if (target == 0) { @@ -924,7 +924,7 @@ namespace winrt::impl { uintptr_t count_or_pointer = m_references.load(std::memory_order_relaxed); - for (;;) + while (true) { if (is_weak_ref(count_or_pointer)) { @@ -1048,7 +1048,7 @@ namespace winrt::impl { uintptr_t count_or_pointer = m_references.load(std::memory_order_relaxed); - for (;;) + while (true) { if (is_weak_ref(count_or_pointer)) { @@ -1198,7 +1198,7 @@ namespace winrt::impl uintptr_t const encoding = encode_weak_ref(weak_ref.get()); - for (;;) + while (true) { if (m_references.compare_exchange_weak(count_or_pointer, encoding, std::memory_order_acq_rel, std::memory_order_relaxed)) { From 9e200c14d8de84abdb8e9f12c5d91d9de5c97d0f Mon Sep 17 00:00:00 2001 From: Rose <83477269+AtariDreams@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:26:43 -0400 Subject: [PATCH 5/5] Initialization --- cppwinrt/cmd_reader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cppwinrt/cmd_reader.h b/cppwinrt/cmd_reader.h index 4c8d2813e..376180eb4 100644 --- a/cppwinrt/cmd_reader.h +++ b/cppwinrt/cmd_reader.h @@ -233,7 +233,7 @@ namespace cppwinrt auto key = open_sdk(); uint32_t index{}; - std::array subkey{}; + std::array subkey; std::array version_parts{}; std::string result;