[PATCH 1/2] gdbsupport: add assertions in array_view

Tom Tromey tom@tromey.com
Mon Oct 25 18:36:33 GMT 2021


>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> From: Simon Marchi <simon.marchi@efficios.com>
Simon> Add assertions to ensure we don't access an array_view out of bounds.
Simon> Enable these assertions only when _GLIBCXX_DEBUG is set, as we did for
Simon> gdb::optional.

Seems like a good idea to me.

Simon> -  { return m_array[index]; }
Simon> +  {
Simon> +#if defined(_GLIBCXX_DEBUG)
Simon> +    gdb_assert (index < m_size);
Simon> +#endif
Simon> +    return m_array[index];

I wonder if I ought to change the new type::field assert to be
conditional like this.  Do we have some rule about which ones should be
conditional on _GLIBCXX_DEBUG?

Or maybe type::fields should return an array view...

Tom


More information about the Gdb-patches mailing list