diff options
| author | Egor Tensin <egor@tensin.name> | 2026-06-05 11:34:11 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-06-05 11:34:11 +0200 |
| commit | 994f91c5c5b1a3ab40bc5545070dab96b6ff0098 (patch) | |
| tree | 4ee7f0ee0fec8c1841bf4d5f30093cb85568ec7a | |
| parent | fix .clang-tidy (diff) | |
| download | winapi-debug-994f91c5c5b1a3ab40bc5545070dab96b6ff0098.tar.gz winapi-debug-994f91c5c5b1a3ab40bc5545070dab96b6ff0098.zip | |
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
| -rw-r--r-- | include/winapi/debug/call_stack.hpp | 11 | ||||
| -rw-r--r-- | src/call_stack.cpp | 4 | ||||
| -rw-r--r-- | 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<Address, max_length> 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<Address, max_length>&& frames, std::size_t length) + : frames{std::move(frames)}, _length{length} {} + + std::array<Address, max_length> 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<Address>(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<std::string> 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<boost::optional<winapi::SymbolInfo>> symbols; - symbols.reserve(call_stack.length); + symbols.reserve(call_stack.length()); BOOST_TEST_MESSAGE("Resolved symbols:"); for (const auto& addr : call_stack) { |
