changeset 27064:d61825e693f2

warn about indexing values with () (bug #56167) * errwarn.h, errwarn.cc (warn_empty_index): New function. * Cell.cc (Cell::index): Use it if indexing with (). * ov-base-mat.cc (octave_base_matrix<MT>::do_index_op): Likewise. * ov-struct.cc (octave_map::do_index_op): Likewise.
author John W. Eaton <jwe@octave.org>
date Tue, 23 Apr 2019 18:46:12 +0000
parents 3140380861ce
children ffdfeb835aef
files libinterp/corefcn/Cell.cc libinterp/corefcn/errwarn.cc libinterp/corefcn/errwarn.h libinterp/octave-value/ov-base-mat.cc libinterp/octave-value/ov-struct.cc
diffstat 5 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/Cell.cc	Tue Apr 23 10:47:02 2019 +0000
+++ b/libinterp/corefcn/Cell.cc	Tue Apr 23 18:46:12 2019 +0000
@@ -166,6 +166,7 @@
       switch (n)
         {
         case 0:
+          warn_empty_index ("cell array");
           retval = *this;
           break;
 
--- a/libinterp/corefcn/errwarn.cc	Tue Apr 23 10:47:02 2019 +0000
+++ b/libinterp/corefcn/errwarn.cc	Tue Apr 23 18:46:12 2019 +0000
@@ -330,6 +330,14 @@
 }
 
 void
+warn_empty_index (const std::string& type_name)
+{
+  warning_with_id ("Octave:empty-index",
+                   "'%s' object indexed with empty index list",
+                   type_name.c_str ());
+}
+
+void
 warn_implicit_conversion (const char *id, const char *from, const char *to)
 {
   warning_with_id (id, "implicit conversion from %s to %s", from, to);
--- a/libinterp/corefcn/errwarn.h	Tue Apr 23 10:47:02 2019 +0000
+++ b/libinterp/corefcn/errwarn.h	Tue Apr 23 18:46:12 2019 +0000
@@ -167,6 +167,9 @@
 warn_empty_arg (const char *name);
 
 OCTINTERP_API extern void
+warn_empty_index (const std::string& type_name);
+
+OCTINTERP_API extern void
 warn_implicit_conversion (const char *id, const char *from, const char *to);
 
 OCTINTERP_API extern void
--- a/libinterp/octave-value/ov-base-mat.cc	Tue Apr 23 10:47:02 2019 +0000
+++ b/libinterp/octave-value/ov-base-mat.cc	Tue Apr 23 18:46:12 2019 +0000
@@ -149,6 +149,7 @@
       switch (n_idx)
         {
         case 0:
+          warn_empty_index (type_name ());
           retval = matrix;
           break;
 
--- a/libinterp/octave-value/ov-struct.cc	Tue Apr 23 10:47:02 2019 +0000
+++ b/libinterp/octave-value/ov-struct.cc	Tue Apr 23 18:46:12 2019 +0000
@@ -539,7 +539,10 @@
 octave_struct::do_index_op (const octave_value_list& idx, bool resize_ok)
 {
   if (idx.length () == 0)
-    return map;
+    {
+      warn_empty_index (type_name ());
+      return map;
+    }
   else  // octave_map handles indexing itself.
     return map.index (idx, resize_ok);
 }