Commit 5e266f5
committed
fix(container_allocator): Fix MSVC error by correcting allocator semantics
ROOT CAUSE:
The allocate() function was incorrectly constructing objects during memory
allocation, violating C++ allocator requirements. MSVC's std::_Tree_node has
a deleted default constructor, causing compilation failure.
CHANGES:
1. container_allocator::allocate() - Now only allocates raw memory without
constructing objects (removed mem::$new and ipc::construct calls)
2. container_allocator::deallocate() - Now only frees memory without
destroying objects (removed mem::$delete and ipc::destroy_n calls)
WHY THIS FIXES THE ISSUE:
- C++ allocator semantics require strict separation:
* allocate() -> raw memory allocation
* construct() -> object construction
* destroy() -> object destruction
* deallocate() -> memory deallocation
- std::map and other containers call construct() with proper arguments
(key, value) to initialize nodes, not allocate()
- std::_Tree_node in MSVC has no default constructor (= delete), so
attempting to construct it without arguments always fails
- The previous code tried to default-construct objects in allocate(),
which is both semantically wrong and impossible for _Tree_node
PREVIOUS FIX (uninitialized.h):
The earlier fix to uninitialized.h was insufficient - even with correct
T() vs T{} handling, you cannot default-construct a type with deleted
default constructor.
Fixes MSVC 2017 compilation error:
error C2280: attempting to reference a deleted function1 parent d65eafe commit 5e266f5
1 file changed
+7
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
76 | 70 | | |
77 | 71 | | |
78 | 72 | | |
79 | 73 | | |
80 | 74 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
86 | 78 | | |
87 | 79 | | |
88 | 80 | | |
| |||
0 commit comments