This is the mail archive of the
mailing list for the GCC project.
Re: [PATCH 005/236] Introduce as_a_nullable
- From: Jeff Law <law at redhat dot com>
- To: David Malcolm <dmalcolm at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Tue, 12 Aug 2014 15:03:05 -0600
- Subject: Re: [PATCH 005/236] Introduce as_a_nullable
- Authentication-results: sourceware.org; auth=none
- References: <1407345815-14551-1-git-send-email-dmalcolm at redhat dot com> <1407345815-14551-6-git-send-email-dmalcolm at redhat dot com>
On 08/06/14 11:19, David Malcolm wrote:
Presumably the cases where we wanted to use as_a on a NULL pointer were
places were we can legitimately have a NULL pointer?
In many circumstances, is_a_helper <T>::test assumes that the pointer is
non-NULL, but sometimes you have a pointer of type T that can be NULL.
Earlier versions of this patch kit made numerous uses of the ternary
operator to handle nullable pointers e.g.:
return insn ? as_a <rtx_insn *> (insn) : NULL;
but this was ugly. Instead, introduce an as_a_nullable<T> variant that
adds a check for NULL, so the above can be written simply as:
return as_a_nullable <rtx_insn *> (insn);
* is-a.h (template<T, U> as_a_nullable <U *p>) New function.
I guess since they'll be using as_a_nullable, they're effectively
documented as potentially being NULL and we can go back and look at them
at a future date.