2017_12_27 Louis Krupp <louis.krupp@zoho.com>
authorLouis Krupp <louis.krupp@zoho.com>
Wed, 27 Dec 2017 19:20:12 +0000 (19:20 +0000)
committerLouis Krupp <lkrupp@gcc.gnu.org>
Wed, 27 Dec 2017 19:20:12 +0000 (19:20 +0000)
PR fortran/83092
* expr.c (gfc_apply_init): Check that typespec has character type
before using character length field.

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

PR fortran/83092
* gfortran.dg/init_char_with_nonchar_ctr.f90: New test.

From-SVN: r256011

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

index c28f4fee6f304adb1ed5278f5ac085d1e6615dd2..91771e0d6699a74a331e654d3fe55efd8727113d 100644 (file)
@@ -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 428fce1ad045af2276465b1ab6bd37265b902626..2cdd46522ed34c71d216d12fce724b4c7ab0b08b 100644 (file)
@@ -4208,6 +4208,7 @@ gfc_apply_init (gfc_typespec *ts, symbol_attribute *attr, gfc_expr *init)
       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 53f61f105dd3769084f90d57ad8327743bb72dfe..f8fcc47ad7a0ab829e5aac4a476fe299131a0e87 100644 (file)
@@ -1,3 +1,8 @@
+2017_12_27  Louis Krupp  <louis.krupp@zoho.com>
+
+       PR fortran/83092
+       * gfortran.dg/init_char_with_nonchar_ctr.f90: New test.
+
 2017-12-27  Kugan Vivekanandarajah  <kuganv@linaro.org>
 
        * gcc.target/aarch64/advsimd-intrinsics/vld1x2.c: New test.
diff --git a/gcc/testsuite/gfortran.dg/init_char_with_nonchar_ctr.f90 b/gcc/testsuite/gfortran.dg/init_char_with_nonchar_ctr.f90
new file mode 100644 (file)
index 0000000..b84a9a8
--- /dev/null
@@ -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