This is the mail archive of the 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]

Re: [patch] Make vector::at() assertion message more useful (try #2)

On Fri, Sep 13, 2013 at 3:02 AM, Paolo Carlini <> wrote:

> - The game with the variadic and the non-variadic __throw_out_of_range makes
> me a little nervous. Let's just name the new one differently, like
> __throw_out_of_range_var.

Replaced with __throw_out_of_range_fmt.

> - Please consistently use __builtin_alloca everywhere, alloca isn't a
> standard function.


> - I would rather call the file itself, in order not to fool
> somebody that it actually implements the whole snprintf.


> - I'm a bit confused about __concat_size_t returning -1. Since it only
> formats integers, I think we can be *sure* that the buffer is big enough.

How so? The caller could do this:

  __snprintf_lite("aaa: %zu, 8, 12345678);

By the time we get to __concat_size_t, we only have 3 characters left.

> Then, if it returns -1 something is going *very badly* wrong, shouldn't we
> __builtin_abort() or something similar?

I've re-worked this part -- if this ever happens, throw a logic_error with
a message to file a bug.

> - In terms of buffer sizes, this comment:
>     // enough for expanding up to 5 size_t's in the format.
> and then the actual code in __snprintf_lite makes me a little nervous.
> Agreed, we are not going to overflow the buffer, but truncating with no
> diagnostic whatsoever seems rather gross. We can probably sort out this
> later, new ideas welcome, anyway.


> - While we are at it, shouldn't we use the new facility at least in array,
> vector<bool> and deque too? For consistency over the containers.


I also expanded snprintf_lite to handle '%s', as that comes handy inside
string _M_check.


P.S. In the process of updating callers of __throw_out_of_range, I've
discovered that two of them had already used __builtin_sprintf.

P.P.S. Sorry this patch grew ... I can split it into parts if that's easier
to review.

Paul Pluzhnikov


	* include/bits/functexcept.h (__throw_out_of_range_fmt): New.
	* src/c++11/ (__throw_out_of_range_fmt): New.
	* src/c++11/ New.
	* src/c++11/ Add
	* src/c++11/ Regenerate.
	* config/abi/pre/gnu.ver: Add _ZSt24__throw_out_of_range_fmtPKcz.
	* include/std/array (at): Use __throw_out_of_range_fmt.
	* include/debug/array (at): Likewise.
	* include/profile/array (at): Likewise.
	* include/std/bitset (_M_check_initial_position, _M_check): New.
	(bitset::bitset): Use _M_check_initial_position.
	(set, reset, flip, test): Use _M_check.
	* include/ext/vstring.h (_M_check, at): Use __throw_out_of_range_fmt.
	* include/bits/stl_vector.h (_M_range_check): Likewise.
	* include/bits/stl_bvector.h (_M_range_check): Likewise.
	* include/bits/stl_deque.h (_M_range_check): Likewise.
	* include/bits/basic_string.h (_M_check, at): Likewise.
	* testsuite/23_containers/vector/requirements/dr438/ Adjust.
	* testsuite/23_containers/vector/requirements/dr438/ Likewise.
	* testsuite/23_containers/vector/requirements/dr438/
	* testsuite/23_containers/vector/requirements/dr438/
	* testsuite/23_containers/deque/requirements/dr438/ Likewise.
	* testsuite/23_containers/deque/requirements/dr438/ Likewise.
	* testsuite/23_containers/deque/requirements/dr438/
	* testsuite/23_containers/deque/requirements/dr438/
	* testsuite/23_containers/array/tuple_interface/ Likewise.
	* testsuite/23_containers/array/tuple_interface/ Likewise.
	* testsuite/util/exception/safety.h (generate): Use __throw_out_of_range_fmt.

Attachment: gcc-20130918.txt
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]