This is the mail archive of the
mailing list for the GCC project.
Re: [patch] Make vector::at() assertion message more useful (try #2)
- From: Paul Pluzhnikov <ppluzhnikov at google dot com>
- To: Daniel Krügler <daniel dot kruegler at gmail dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>, "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 4 Sep 2013 16:16:34 -0700
- Subject: Re: [patch] Make vector::at() assertion message more useful (try #2)
- Authentication-results: sourceware.org; auth=none
- References: <ye6qhae0qpf8 dot fsf at elbrus2 dot mtv dot corp dot google dot com> <CAGNvRgDfHf6pYmBYC66HHhj6RobhiaiAAVEKj1FDxSWGxbYFTg at mail dot gmail dot com>
On Wed, Sep 4, 2013 at 2:10 PM, Daniel Krügler
> I expect that this kind of index violation is a rather often occurring
> pattern and should be isolated. IMO the _M_range
> _check now pessimisms the normal, non-violating case.
Did you mean "pessimises code size", or something else?
> Why not simply
> replacing it by something along the lines of
> _M_range_check(size_type __n) const
> if (__n >= this->size())
> __n, this->size()));
> where __index_out_of_range_msg is a reusable function that uses
> something like snprintf_lite internally?
Some disadvantages to doing that:
1. The actual message is now "magically" transformed inside
__index_out_of_range_msg into the final message, making translation
2. __index_out_of_range_msg() would have to return a string, which is heavier
weight (in try#1 I just used snprintf, which was considered "too heavy").