# HG changeset patch # User John W. Eaton # Date 1712933268 14400 # Node ID c9517a0c9cc20b8fb725d486d428571535f75bea # Parent 7e7d52c1e03acb8b41bfedc6a4f41addd31a0281 rely on compiler warnings for unhandled enum switch cases in idx_vector class * idx-vector.h, idx-vector.cc: Don't use default cases in switch statements that use enum values so that compilers may warn about unhandled enum values. Use error to report enum values that are not accepted by the switch, use error with a meaningful message instead of panic_impossible. diff -r 7e7d52c1e03a -r c9517a0c9cc2 liboctave/array/idx-vector.cc --- a/liboctave/array/idx-vector.cc Fri Apr 12 10:21:16 2024 -0400 +++ b/liboctave/array/idx-vector.cc Fri Apr 12 10:47:48 2024 -0400 @@ -1042,6 +1042,10 @@ switch (m_rep->idx_class ()) { + case class_invalid: + (*current_liboctave_error_handler) ("unexpected: invalid index"); + break; + case class_colon: (*current_liboctave_error_handler) ("colon not allowed"); break; @@ -1087,9 +1091,9 @@ } break; - default: - liboctave_panic_impossible (); - break; + // We should have handled all possible enum values above. Rely on + // compiler diagnostics to warn if we haven't. For example, GCC's + // -Wswitch option, enabled by -Wall, will provide a warning. } } @@ -1220,6 +1224,10 @@ iclass = idx_class (); switch (iclass) { + case class_invalid: + (*current_liboctave_error_handler) ("unexpected: invalid index"); + break; + case class_colon: break; @@ -1251,9 +1259,9 @@ } break; - default: - liboctave_panic_impossible (); - break; + // We should have handled all possible enum values above. Rely on + // compiler diagnostics to warn if we haven't. For example, GCC's + // -Wswitch option, enabled by -Wall, will provide a warning. } } diff -r 7e7d52c1e03a -r c9517a0c9cc2 liboctave/array/idx-vector.h --- a/liboctave/array/idx-vector.h Fri Apr 12 10:21:16 2024 -0400 +++ b/liboctave/array/idx-vector.h Fri Apr 12 10:47:48 2024 -0400 @@ -587,6 +587,10 @@ switch (m_rep->idx_class ()) { + case class_invalid: + (*current_liboctave_error_handler) ("unexpected: invalid index"); + break; + case class_colon: std::copy_n (src, len, dest); break; @@ -637,9 +641,10 @@ } break; - default: - liboctave_panic_impossible (); - break; + // We should have handled all possible enum values above. Rely + // on compiler diagnostics to warn if we haven't. For example, + // GCC's -Wswitch option, enabled by -Wall, will provide a + // warning. } return len; @@ -661,6 +666,10 @@ switch (m_rep->idx_class ()) { + case class_invalid: + (*current_liboctave_error_handler) ("unexpected: invalid index"); + break; + case class_colon: std::copy_n (src, len, dest); break; @@ -709,9 +718,10 @@ } break; - default: - liboctave_panic_impossible (); - break; + // We should have handled all possible enum values above. Rely + // on compiler diagnostics to warn if we haven't. For example, + // GCC's -Wswitch option, enabled by -Wall, will provide a + // warning. } return len; @@ -733,6 +743,10 @@ switch (m_rep->idx_class ()) { + case class_invalid: + (*current_liboctave_error_handler) ("unexpected: invalid index"); + break; + case class_colon: std::fill_n (dest, len, val); break; @@ -781,9 +795,10 @@ } break; - default: - liboctave_panic_impossible (); - break; + // We should have handled all possible enum values above. Rely + // on compiler diagnostics to warn if we haven't. For example, + // GCC's -Wswitch option, enabled by -Wall, will provide a + // warning. } return len; @@ -803,6 +818,10 @@ switch (m_rep->idx_class ()) { + case class_invalid: + (*current_liboctave_error_handler) ("unexpected: invalid index"); + break; + case class_colon: for (octave_idx_type i = 0; i < len; i++) body (i); break; @@ -847,9 +866,10 @@ } break; - default: - liboctave_panic_impossible (); - break; + // We should have handled all possible enum values above. Rely + // on compiler diagnostics to warn if we haven't. For example, + // GCC's -Wswitch option, enabled by -Wall, will provide a + // warning. } } @@ -871,6 +891,10 @@ switch (m_rep->idx_class ()) { + case class_invalid: + (*current_liboctave_error_handler) ("unexpected: invalid index"); + break; + case class_colon: { octave_idx_type i; @@ -933,9 +957,10 @@ } break; - default: - liboctave_panic_impossible (); - break; + // We should have handled all possible enum values above. Rely + // on compiler diagnostics to warn if we haven't. For example, + // GCC's -Wswitch option, enabled by -Wall, will provide a + // warning. } return ret;