From 994f91c5c5b1a3ab40bc5545070dab96b6ff0098 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 5 Jun 2026 11:34:11 +0200 Subject: fix weird errors For some reason, I can no longer initialize a CallStack instance from an initializer list. On CI, it works fine; maybe my compiler is newer and somehow defaults to a newer standard or something? Idk --- include/winapi/debug/call_stack.hpp | 11 ++++++++--- src/call_stack.cpp | 4 ++-- test/unit_tests/call_stack.cpp | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/winapi/debug/call_stack.hpp b/include/winapi/debug/call_stack.hpp index e5b8c41..a9a9d43 100644 --- a/include/winapi/debug/call_stack.hpp +++ b/include/winapi/debug/call_stack.hpp @@ -38,16 +38,21 @@ public: void dump(std::ostream& os, const DbgHelp&) const; - const std::array frames; - const std::size_t length; + std::size_t length() const { return _length; } const Address* begin() const { return frames.data(); } const Address* cbegin() const { return begin(); } - const Address* end() const { return begin() + length; } + const Address* end() const { return begin() + _length; } const Address* cend() const { return end(); } private: CallStack() = default; + + CallStack(std::array&& frames, std::size_t length) + : frames{std::move(frames)}, _length{length} {} + + std::array frames; + std::size_t _length; }; } // namespace winapi diff --git a/src/call_stack.cpp b/src/call_stack.cpp index 4a13b3a..e69c10d 100644 --- a/src/call_stack.cpp +++ b/src/call_stack.cpp @@ -89,11 +89,11 @@ CallStack CallStack::capture() { std::transform(frames_impl.cbegin(), frames_impl.cend(), frames.begin(), [](void* addr) { return reinterpret_cast
(addr); }); - return {frames, length}; + return {std::move(frames), length}; } bool CallStack::for_each_address(const AddressCallback& callback) const { - for (std::size_t i = 0; i < length; ++i) { + for (std::size_t i = 0; i < _length; ++i) { if (!callback(frames[i])) { return false; } diff --git a/test/unit_tests/call_stack.cpp b/test/unit_tests/call_stack.cpp index 039e8f9..8195137 100644 --- a/test/unit_tests/call_stack.cpp +++ b/test/unit_tests/call_stack.cpp @@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(call_stack) { // Debug output: std::vector pretty; - pretty.reserve(call_stack.length); + pretty.reserve(call_stack.length()); BOOST_TEST_MESSAGE("Call stack:"); for (const auto& addr : call_stack) { @@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(call_stack) { // Second, resolve the symbols: std::vector> symbols; - symbols.reserve(call_stack.length); + symbols.reserve(call_stack.length()); BOOST_TEST_MESSAGE("Resolved symbols:"); for (const auto& addr : call_stack) { -- cgit v1.3