changeset 27060:3140380861ce

error for x{} for cell array objects (bug #56167) * ov-cell.cc (octave_cell::subsref): Error for empty {} index expression. * Cell.cc: Update test. Note Matlab compatibility requirement. * ov-base-mat.cc: New test.
author John W. Eaton <jwe@octave.org>
date Tue, 23 Apr 2019 10:47:02 +0000
parents 2bf6dcb1563c
children d61825e693f2
files libinterp/corefcn/Cell.cc libinterp/octave-value/ov-base-mat.cc libinterp/octave-value/ov-cell.cc
diffstat 3 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/Cell.cc	Mon Apr 22 21:53:52 2019 -0700
+++ b/libinterp/corefcn/Cell.cc	Tue Apr 23 10:47:02 2019 +0000
@@ -211,9 +211,11 @@
 }
 
 /*
-%!test
+%% This behavior is required for Matlab compatibility.
+%!shared a
 %! a = {"foo", "bar"};
-%! assert (a(), a);
+%!assert (a(), a);
+%!error <invalid empty index expression> a{}
 */
 
 void
--- a/libinterp/octave-value/ov-base-mat.cc	Mon Apr 22 21:53:52 2019 -0700
+++ b/libinterp/octave-value/ov-base-mat.cc	Tue Apr 23 10:47:02 2019 +0000
@@ -210,6 +210,13 @@
   return retval;
 }
 
+/*
+%% This behavior is required for Matlab compatibility.
+%!test
+%! a = [1, 2; 3, 4];
+%! assert (a(), a);
+*/
+
 template <typename MT>
 void
 octave_base_matrix<MT>::assign (const octave_value_list& idx, const MT& rhs)
--- a/libinterp/octave-value/ov-cell.cc	Mon Apr 22 21:53:52 2019 -0700
+++ b/libinterp/octave-value/ov-cell.cc	Tue Apr 23 10:47:02 2019 +0000
@@ -157,6 +157,9 @@
 
     case '{':
       {
+        if (idx.front ().empty ())
+          error ("invalid empty index expression");
+
         octave_value tmp = do_index_op (idx.front ());
 
         Cell tcell = tmp.cell_value ();