Repository navigation
Prevent byte relocation of non-trivial VLA elements - #217
Merged
thirtytwobits merged 7 commits intoOct 6, 2026
Merged
thirtytwobits merged 7 commits into
thirtytwobits merged 7 commits into
Conversation
Cover reserve, shrink, implicit growth, trivial storage, packed bool, and relocation rollback before fixing issue #213. The unchanged implementation fails 14 of 22 tests with exceptions and 10 of 18 tests without exceptions.
Reserve setup storage in the assignment and fill-resize tests. Add a regression proving that safe relocation retains the original array when replacement storage is unavailable; verified failing against the issue #37 header.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused safety fix is consistent with allocator behavior and is covered across relevant element types and failure paths.
Review effort: Balanced
Findings: None
What changed in this PR
Prevents unsafe byte relocation of non-trivial VLA elements while retaining optimized reallocation for trivial and packed-bool storage.
Changes:
- Gates allocator reallocation on trivial copyability.
- Documents capacity behavior for single-allocation resources.
- Adds comprehensive relocation, failure, and lifetime tests.
| File | Description |
|---|---|
include/cetl/variable_length_array.hpp |
Adds the safe reallocation gate and documentation. |
cetlvast/suites/unittest/test_variable_length_array_reallocation.cpp |
Tests relocation safety and failure handling. |
cetlvast/suites/unittest/test_variable_length_array_general_allocation.cpp |
Updates fixed-buffer tests and covers replacement-storage limits. |
cetlvast/suites/unittest/CMakeLists.txt |
Registers the new test suite. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Centralize scenario capacities, element counts, payloads, packed-bit patterns, and sentinels. Derive loop bounds and expectations, and assert the relationships required for relocation and failure coverage. Validate alternate numeric configurations and compile-time rejection of invalid ones. #verification
Keep resource and lifetime recorders non-copyable and non-movable. Explicitly default or delete the remaining special members on relocation elements while retaining their tested lifetime and copy/move traits. #verification
Record targeted suppressions for intentional raw allocation and the test-only exception sentinel, clarify packed-count grouping, and make saved pointer declarations explicit. #verification
thirtytwobits
added this pull request to stack #216
October 6, 2026 20:24
pavel-kirienko
approved these changes
Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
reserve()andshrink_to_fit()could pass live non-trivially-copyable elements to an allocator'sreallocate, which may move the block by copying bytes. Address-sensitive elements then retained pointers into released storage, and element constructors/destructors were bypassed.Gate the shared reallocation helper on
std::is_trivially_copyable<value_type>. Other elements use the existing allocator-aware relocation and rollback from #215. Trivial storage and packed bool retain reallocation support. Non-trivial elements now require replacement storage for capacity changes, including when the underlying resource could resize in place; the public documentation explains reserving capacity up front for single-allocation resources.Stacked on #215 (
codex/issue-37-vla-partial-construction, base commit38027ab). The implementation remains self-contained.Tests were written, run against the unchanged implementation, and committed before the fix:
59fbcab: deterministic moving-resource regressions for reserve, shrink, implicit growth, address-sensitive elements, move-only/copy-fallback lifetimes, allocation and construction failures, trivial storage, packed bool, and allocators without reallocate.90ed933: single-allocation resource behavior, plus explicit capacity setup in existing copy-assignment and fill-resize tests that previously relied on non-trivial in-place growth.dc8e9c4: production gate and documentation.The reallocation suite centralizes numeric scenario inputs and derives sizes, payloads, packed capacities, and lifetime expectations from them. Static assertions protect the relocation, failure-position, bit-pattern, and numeric-range requirements; implicit resize derives its target from the capacity obtained after append.
Validation:
git diff --checkpassed. Doxygen completed with the same 13 pre-existing warnings in type_traits_ext.hpp and unbounded_variant.hpp.Closes #213 after this stack is merged into the default branch.