Possible patch for fortran/83092

Louis Krupp louis.krupp@zoho.com
Wed Dec 27 11:03:00 GMT 2017


2017_12_27  Louis Krupp  <louis.krupp@zoho.com>

        PR fortran/83092
        * expr.c (gfc_apply_init): Check that typespec has character type
        before using character length field.

Louis Krupp 
  
-------------- next part --------------
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(revision 256009)
+++ gcc/fortran/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2017_12_27  Louis Krupp  <louis.krupp@zoho.com>
+
+	PR fortran/83092
+	* expr.c (gfc_apply_init): Check that typespec has character type
+	before using character length field.
+
 2017-12-26  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
 	PR fortran/83540
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 256009)
+++ gcc/fortran/expr.c	(working copy)
@@ -4208,6 +4208,7 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute
       if (init->expr_type == EXPR_CONSTANT)
         gfc_set_constant_character_len (len, init, -1);
       else if (init
+	       && init->ts.type == BT_CHARACTER
                && init->ts.u.cl
                && mpz_cmp (ts->u.cl->length->value.integer,
                            init->ts.u.cl->length->value.integer))
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(revision 256009)
+++ gcc/testsuite/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2017_12_27  Louis Krupp  <louis.krupp@zoho.com>
+
+	PR fortran/83092
+	* gfortran.dg/pr83092.f90: New test.
+
 2017-12-27  Martin Liska  <mliska@suse.cz>
 
 	PR tree-optimization/83552
Index: gcc/testsuite/gfortran.dg/pr83092.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr83092.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr83092.f90	(working copy)
@@ -0,0 +1,34 @@
+! { dg-do compile }
+
+! Initialization of character by non-character constructor
+
+subroutine s1
+   type t
+      integer :: n = 0
+   end type
+   type t2
+      character :: c = t() ! { dg-error "Can't convert TYPE\\(t\\) to CHARACTER\\(1\\)" }
+   end type
+end subroutine
+
+subroutine s2
+   type t
+   end type
+   type t2
+      character :: c(1) = [t()] ! { dg-error "Can't convert TYPE\\(t\\) to CHARACTER\\(1\\)" }
+   end type
+end subroutine
+
+subroutine s3
+   type t
+      integer :: a = 1
+      character :: c = t() ! { dg-error "Can't convert TYPE\\(t\\) to CHARACTER\\(1\\)" }
+   end type
+end subroutine
+
+subroutine s4
+   type t
+      integer, allocatable :: a
+      character :: c = t() ! { dg-error "Can't convert TYPE\\(t\\) to CHARACTER\\(1\\)" }
+   end type
+end subroutine


More information about the Fortran mailing list