comparison libinterp/corefcn/data.cc @ 33344:3606817b9994

take adavantage of compiler warnings for unhandled enum switch cases 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.
author John W. Eaton <jwe@octave.org>
date Sat, 06 Apr 2024 14:38:17 -0400
parents 59ee9d370307
children fb44a9db1bc6
comparison
equal deleted inserted replaced
33343:eb8a24370c2b 33344:3606817b9994
654 MAKE_INT_BRANCH (uint32); 654 MAKE_INT_BRANCH (uint32);
655 MAKE_INT_BRANCH (uint64); 655 MAKE_INT_BRANCH (uint64);
656 656
657 #undef MAKE_INT_BRANCH 657 #undef MAKE_INT_BRANCH
658 658
659 default: 659 case btyp_double:
660 panic_impossible (); 660 case btyp_float:
661 case btyp_complex:
662 case btyp_float_complex:
663 case btyp_bool:
664 case btyp_char:
665 case btyp_struct:
666 case btyp_cell:
667 case btyp_func_handle:
668 case btyp_unknown:
669 error ("rem: unexpected: found %s instead of integer - please report this bug", btyp_class_name[btyp0].c_str ());
670 break;
671
672 // We should have handled all possible enum values above.
673 // Rely on compiler diagnostics to warn if we haven't. For
674 // example, GCC's -Wswitch option, enabled by -Wall, will
675 // provide a warning.
661 } 676 }
662 } 677 }
663 else if (args(0).is_single_type () || args(1).is_single_type ()) 678 else if (args(0).is_single_type () || args(1).is_single_type ())
664 { 679 {
665 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) 680 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
838 MAKE_INT_BRANCH (uint32); 853 MAKE_INT_BRANCH (uint32);
839 MAKE_INT_BRANCH (uint64); 854 MAKE_INT_BRANCH (uint64);
840 855
841 #undef MAKE_INT_BRANCH 856 #undef MAKE_INT_BRANCH
842 857
843 default: 858 case btyp_double:
844 panic_impossible (); 859 case btyp_float:
860 case btyp_complex:
861 case btyp_float_complex:
862 case btyp_bool:
863 case btyp_char:
864 case btyp_struct:
865 case btyp_cell:
866 case btyp_func_handle:
867 case btyp_unknown:
868 error ("mod: unexpected: found %s instead of integer - please report this bug", btyp_class_name[btyp0].c_str ());
869 break;
870
871 // We should have handled all possible enum values above.
872 // Rely on compiler diagnostics to warn if we haven't. For
873 // example, GCC's -Wswitch option, enabled by -Wall, will
874 // provide a warning.
845 } 875 }
846 } 876 }
847 else if (args(0).is_single_type () || args(1).is_single_type ()) 877 else if (args(0).is_single_type () || args(1).is_single_type ())
848 { 878 {
849 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) 879 if (args(0).is_scalar_type () && args(1).is_scalar_type ())