]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: generate regular error on invalid conversions of CASE expressions
authorSteve Kargl <kargl@gcc.gnu.org>
Sat, 30 Oct 2021 16:22:19 +0000 (18:22 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 30 Oct 2021 16:22:19 +0000 (18:22 +0200)
gcc/fortran/ChangeLog:

PR fortran/99853
* resolve.c (resolve_select): Generate regular gfc_error on
invalid conversions instead of an gfc_internal_error.

gcc/testsuite/ChangeLog:

PR fortran/99853
* gfortran.dg/pr99853.f90: New test.

gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/pr99853.f90 [new file with mode: 0644]

index af71b132deca40c8cffd70b2957de3204e546fe2..8da396b32ecbb571e803ff949ce40e14fa935f8d 100644 (file)
@@ -8770,11 +8770,11 @@ resolve_select (gfc_code *code, bool select_type)
 
              if (cp->low != NULL
                  && case_expr->ts.kind != gfc_kind_max(case_expr, cp->low))
-               gfc_convert_type_warn (case_expr, &cp->low->ts, 2, 0);
+               gfc_convert_type_warn (case_expr, &cp->low->ts, 1, 0);
 
              if (cp->high != NULL
                  && case_expr->ts.kind != gfc_kind_max(case_expr, cp->high))
-               gfc_convert_type_warn (case_expr, &cp->high->ts, 2, 0);
+               gfc_convert_type_warn (case_expr, &cp->high->ts, 1, 0);
            }
         }
     }
diff --git a/gcc/testsuite/gfortran.dg/pr99853.f90 b/gcc/testsuite/gfortran.dg/pr99853.f90
new file mode 100644 (file)
index 0000000..421a656
--- /dev/null
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! { dg-options "-std=f2018" }
+! PR fortran/99853
+
+subroutine s1 ()
+  select case (.true.) ! { dg-error "Cannot convert" }
+  case (1_8)           ! { dg-error "must be of type LOGICAL" }
+  end select
+end
+
+subroutine s2 ()
+  select case (.false._1) ! { dg-error "Cannot convert" }
+  case (2:3)              ! { dg-error "must be of type LOGICAL" }
+  end select
+end
+
+subroutine s3 ()
+  select case (3_2) ! { dg-error "Cannot convert" }
+  case (.false.)    ! { dg-error "must be of type INTEGER" }
+  end select
+end
+
+subroutine s4 (i)
+  select case (i) ! { dg-error "Cannot convert" }
+  case (.true._8) ! { dg-error "must be of type INTEGER" }
+  end select
+end
+
+! { dg-prune-output "Cannot convert" }