Opened 5 years ago
#13201 new Bugs
boost::container::small_vector invalid internal capacity
Reported by: | Owned by: | Ion Gaztañaga | |
---|---|---|---|
Milestone: | To Be Determined | Component: | container |
Version: | Boost 1.65.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Sometimes the internal capacity of the small_vector is smaller than the specified. Take the following example:
#include <boost/container/small_vector.hpp> #include <iostream> int main() { boost::container::small_vector<char, 15> v{ 0 }; boost::container::small_vector<char, 15> v2(15); std::cout << &v << ' ' << (void*)&v[0] << ' ' << v.capacity() << ' ' << decltype(v)::static_capacity << '\n'; std::cout << &v2 << " " << (void*)&v2[0] << ' ' << v2.capacity() << ' ' << decltype(v2)::static_capacity << '\n'; }
Output on amd64 linux (with clang 4.0.1, but gcc exhibits the same behavior):
0x7ffe053c4700 0x7ffe053c4718 8 15 0x7ffe053c46c8 0xbbfc20 23 15
On 32-bit (-m32):
0xffdfecb0 0xffdfecbc 12 15 0xffdfec88 0x86aea10 27 15
Even though the capacity should be 15, it's 8 on 64-bit and 12 on 32-bit, while static_capacity reports 15. When actually trying to put 15 elements into the vector, it allocates memory from heap.
Note:
See TracTickets
for help on using tickets.