diff libinterp/octave-value/ov.cc @ 22390:6cbbd550aa91

allow subsasgn (x, idx, zeros(0,0)) to remove elements (bug #48867) * ov.cc: If RHS argument is a double 0x0 object, convert it to an octave_null_matrix object in call to octave_value::subsasgn. New test.
author John W. Eaton <jwe@octave.org>
date Thu, 25 Aug 2016 18:18:20 -0400
parents d0562b3159c7
children 48c00363dc74
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc	Thu Aug 25 16:25:46 2016 -0400
+++ b/libinterp/octave-value/ov.cc	Thu Aug 25 18:18:20 2016 -0400
@@ -3162,10 +3162,15 @@
   else
     {
       octave_value arg0 = args(0);
+      octave_value arg2 = args(2);
 
       arg0.make_unique ();
 
-      return ovl (arg0.subsasgn (type, idx, args(2)));
+      bool arg2_null = arg2.is_zero_by_zero () && arg2.is_double_type ();
+
+      return ovl (arg0.subsasgn (type, idx, (arg2_null
+                                             ? octave_null_matrix::instance
+                                             : arg2)));
     }
 }
 
@@ -3192,6 +3197,10 @@
 %! assert (a, b);
 
 %!test
+%! x = 1:10;
+%! assert (subsasgn (x, substruct ("()", {1}), zeros (0, 0)), 2:10);
+
+%!test
 %! c = num2cell (reshape ([1:25],5,5));
 %! idx1 = substruct  ("{}", {3, 3});
 %! idx2 = substruct  ("()", {2:2:5, 2:2:5});