From: feedable <[email protected]>

array_slice has a way to express an invalid value. This is useful for
obvious reasons, but the way to create one is not simple. Currently, to
create an invalid array, one has to specify the exact type of the array
the user wants first, and then the name of the static method, like so:
`do_stuff (array_slice<HARD_REG_SET>::invalid ())`. This is needlessly
long, and the syntax is distracting from the logic of the call site.

Introduce an implicit conversion constructor from `nullptr` to rectify:
now the same call site can be written as `do_stuff (nullptr)`, which is
less cluttered and expresses intent more directly.

gcc/ChangeLog:

        * vec.h: Add conversion from nullptr
---
 gcc/vec.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/vec.h b/gcc/vec.h
index 0d4cffd0c3a61..a2ff7a9b77694 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -2380,6 +2380,8 @@ public:
 
   array_slice () : m_base (nullptr), m_size (0) {}
 
+  array_slice (std::nullptr_t) : array_slice (array_slice::invalid ()) {}
+
   template<typename OtherT>
   array_slice (array_slice<OtherT> other)
     : m_base (other.m_base), m_size (other.m_size) {}
-- 
2.54.0

Reply via email to