This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
>20.4.1.1 allocator members
>
>2/
> pointer allocator(size_type n, allocator<void>::const_pointer = 0);
>
>7/
> Throws: bad_alloc if the storage cannot be obtained
Got it, thanks for the clarification.
>int main()
>{
> try {
> std::allocator<int> alloc;
> const std::allocator<int>::size_type n = alloc.max_size();
> int* p = alloc.allocate(n + 1);
> p[n] = 2002;
> std::cout << p[n] << std::endl;
> } catch(const std::bad_alloc& e) {
> std::cerr << e.what() << std::endl;
> }
>}
>This coredumps on my machine using current source. The problem here is
>that std::allocator<> is not checking the bounds as required and it is
>lying.
Correct, with the pool allocators. If you add GLIBCPP_FORCE_NEW
everything is ok.
See attached patch for a way to fix this with the pool allocators.
>
>I'm also nervous about:
>
> std::vector<int> v;
> v.resize(v.max_size());
>
> v[v.max_size() - 1] = 2002;
>
>I didn't test it with your patch.
My patch is only for reserve, as it's expected to throw length_error.
I believe it's still correct, regardless of resolving this issue.
For resize, the above issue comes into play.
On a completely unrelated note, what's up with std::vector and all the gooey
allocator typedefs? Ick.
The allocator_type typedef is always allocator, as far as I can tell.
And _Alloc_type (should be __underlying_allocator or whatever) seems
superfluous. Instead of typedefing the base type all the time, with g++
one can just use the name of the template proper. There's got to be a
cleaner way to do a lot of this. Matt?
best,
benjamin
Attachment:
p.20021114-1
Description: Binary data
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |