Mercurial > hg > octave-nkf
changeset 20399:b2532deba721
Return copy of class object when using null indexing (bug #44940).
* ov-classdef.cc (cdef_object_scalar::subsref): Check index expression and
return octave_value of this_obj if empty.
* ov-classdef.cc (cdef_object_array::subsref): Remove error when index
expression is empty. If expression is empty then return cdef_object of this.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 14 May 2015 08:00:53 -0700 |
parents | 89616a98b02e |
children | 38487298513b |
files | libinterp/octave-value/ov-classdef.cc |
diffstat | 1 files changed, 22 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-classdef.cc +++ b/libinterp/octave-value/ov-classdef.cc @@ -1476,17 +1476,26 @@ case '(': { + const octave_value_list& ival = idx.front (); + refcount++; - cdef_object this_obj (this); - Array<cdef_object> arr (dim_vector (1, 1), this_obj); - - cdef_object new_obj = cdef_object (new cdef_object_array (arr)); - - new_obj.set_class (get_class ()); - - retval = new_obj.subsref (type, idx, nargout, skip, cls, auto_add); + if (ival.empty ()) + { + skip++; + retval(0) = to_ov (this_obj); + } + else + { + Array<cdef_object> arr (dim_vector (1, 1), this_obj); + + cdef_object new_obj = cdef_object (new cdef_object_array (arr)); + + new_obj.set_class (get_class ()); + + retval = new_obj.subsref (type, idx, nargout, skip, cls, auto_add); + } } break; @@ -1626,16 +1635,17 @@ case '(': { const octave_value_list& ival = idx.front (); - bool is_scalar = true; - Array<idx_vector> iv (dim_vector (1, ival.length ())); if (ival.empty ()) { - ::error ("can't index %s object(s) with empty parentheses", - class_name ().c_str ()); + refcount++; + retval(0) = to_ov (cdef_object (this)); break; } + bool is_scalar = true; + Array<idx_vector> iv (dim_vector (1, ival.length ())); + for (int i = 0; ! error_state && i < ival.length (); i++) { iv(i) = ival(i).index_vector ();