]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: BOZ literal constants are not compatible to any type [PR103413]
authorHarald Anlauf <anlauf@gmx.de>
Wed, 26 Oct 2022 19:00:44 +0000 (21:00 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 28 Oct 2022 20:34:12 +0000 (22:34 +0200)
gcc/fortran/ChangeLog:

PR fortran/103413
* symbol.cc (gfc_type_compatible): A boz-literal-constant has no type
and thus is not considered compatible to any type.

gcc/testsuite/ChangeLog:

PR fortran/103413
* gfortran.dg/illegal_boz_arg_4.f90: New test.

(cherry picked from commit f7d28818179247685f3c101f9f2f16366f56309b)

gcc/fortran/symbol.cc
gcc/testsuite/gfortran.dg/illegal_boz_arg_4.f90 [new file with mode: 0644]

index 7a80dfd063b1ba66c0f9e35efd2c07d1659cd3d2..b092813a5c0e773f350e6ac3acb1cf60a2c36025 100644 (file)
@@ -5133,6 +5133,10 @@ gfc_type_compatible (gfc_typespec *ts1, gfc_typespec *ts2)
   bool is_union1 = (ts1->type == BT_UNION);
   bool is_union2 = (ts2->type == BT_UNION);
 
+  /* A boz-literal-constant has no type.  */
+  if (ts1->type == BT_BOZ || ts2->type == BT_BOZ)
+    return false;
+
   if (is_class1
       && ts1->u.derived->components
       && ((ts1->u.derived->attr.is_class
diff --git a/gcc/testsuite/gfortran.dg/illegal_boz_arg_4.f90 b/gcc/testsuite/gfortran.dg/illegal_boz_arg_4.f90
new file mode 100644 (file)
index 0000000..856cfa9
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "-std=f2018" }
+! PR fortran/103413
+! Contributed by G.Steinmetz
+
+program p
+  type t
+     class(*), allocatable :: a
+  end type
+  type(t) :: x
+  allocate (x%a, source=z'1') ! { dg-error "type incompatible" }
+  allocate (x%a, mold=z'1')   ! { dg-error "type incompatible" }
+end