]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/88138 (ICE in gfc_arith_concat, at fortran/arith.c:1007)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 15 Dec 2018 23:57:03 +0000 (23:57 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 15 Dec 2018 23:57:03 +0000 (23:57 +0000)
2018-12-15  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/88138
* decl.c (variable_decl): Check that a derived isn't being assigned
an incompatible entity in an initialization.

2018-12-15  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/88138
* gfortran.dg/pr88138.f90: new test.

From-SVN: r267180

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr88138.f90 [new file with mode: 0644]

index 12b348733ce25641b3313c5fda2851f6b8c4e697..4d35dde14b8537e85719a4eff666f6f9faa7f3a2 100644 (file)
@@ -1,3 +1,9 @@
+2018-12-15  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/88138
+       * decl.c (variable_decl): Check that a derived isn't being assigned
+       an incompatible entity in an initialization.
 2018-12-11  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/88155
index f3b3091e4246d60e0cc9eabff3aca1361290c196..f7b597bc3fd80cace6eb35a82ea45f68bc131015 100644 (file)
@@ -2544,6 +2544,22 @@ variable_decl (int elem)
       goto cleanup;
     }
 
+  /* Before adding a possible initilizer, do a simple check for compatibility
+     of lhs and rhs types.  Assigning a REAL value to a derive type is not a
+     good thing.  */
+  if (current_ts.type == BT_DERIVED && initializer
+      && (gfc_numeric_ts (&initializer->ts)
+         || initializer->ts.type == BT_LOGICAL
+         || initializer->ts.type == BT_CHARACTER))
+    {
+      gfc_error ("Incompatible initialization between a derive type "
+                "entity and an entity with %qs type at %C",
+                 gfc_typename (&initializer->ts));
+      m = MATCH_ERROR;
+      goto cleanup;
+    }
+
+
   /* Add the initializer.  Note that it is fine if initializer is
      NULL here, because we sometimes also need to check if a
      declaration *must* have an initialization expression.  */
index 4b0bb82997a0edd727f5b40780bdc8785fef5920..c9c464fcef2c28534eebedcf5a68b70e33e7ab70 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-15  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/88138
+       * gfortran.dg/pr88138.f90: new test.
+
 2018-12-13  Andreas Krebbel  <krebbel@linux.ibm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gfortran.dg/pr88138.f90 b/gcc/testsuite/gfortran.dg/pr88138.f90
new file mode 100644 (file)
index 0000000..04b826c
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+program p
+   type t
+      character :: c = 'c'
+   end type
+   type(t), parameter :: x  = 1.e1  ! { dg-error "Incompatible initialization between a" }s
+   print *, 'a' // x%c
+end
+! { dg-prune-output "has no IMPLICIT type" }