This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [google gcc-4_7, integration] Add lightweight checks for front()/back() on empty vector
- From: Gerald Pfeifer <gerald at pfeifer dot com>
- To: Paul Pluzhnikov <ppluzhnikov at google dot com>
- Cc: Diego Novillo <dnovillo at google dot com>, gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: Sun, 20 Jan 2013 12:16:36 +0100 (CET)
- Subject: Re: [google gcc-4_7, integration] Add lightweight checks for front()/back() on empty vector
- References: <ye6q4nid3rk3.fsf@elbrus2.mtv.corp.google.com>
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