This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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: [google gcc-4_7, integration] Add lightweight checks for front()/back() on empty vector


On Sat, 19 Jan 2013, Paul Pluzhnikov wrote:
> This patch adds lightweight checks for front()/back() on empty vector.

>        front()
> -      { return *begin(); }
> +      {
> +#if __google_stl_debug_vector
> +        if (empty()) __throw_logic_error("begin() on empty vector");

Isn't the error message wrong, then?  begin() on an empty vector
is perfectly fine, isn't it?  *begin() is the problem here, so
should this say

           if (empty()) __throw_logic_error("front() on empty vector");

instead?

> +#if __google_stl_debug_vector
> +        if (empty()) __throw_logic_error("back() on empty vector");
> +#endif

In the symmetric case you're already using back(), not end().

Gerald


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