From aefd636b3cc00e1aa37537f9fa3a8381883a1d19 Mon Sep 17 00:00:00 2001 From: Louis Krupp Date: Wed, 27 Dec 2017 19:20:12 +0000 Subject: [PATCH] 2017_12_27 Louis Krupp PR fortran/83092 * expr.c (gfc_apply_init): Check that typespec has character type before using character length field. 2017_12_27 Louis Krupp PR fortran/83092 * gfortran.dg/init_char_with_nonchar_ctr.f90: New test. From-SVN: r256011 --- gcc/fortran/ChangeLog | 6 ++++ gcc/fortran/expr.c | 1 + gcc/testsuite/ChangeLog | 5 +++ .../init_char_with_nonchar_ctr.f90 | 34 +++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/init_char_with_nonchar_ctr.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index c28f4fee6f3..91771e0d669 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017_12_27 Louis Krupp + + PR fortran/83092 + * expr.c (gfc_apply_init): Check that typespec has character type + before using character length field. + 2017-12-26 Thomas Koenig PR fortran/83540 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 428fce1ad04..2cdd46522ed 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 53f61f105dd..f8fcc47ad7a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017_12_27 Louis Krupp + + PR fortran/83092 + * gfortran.dg/init_char_with_nonchar_ctr.f90: New test. + 2017-12-27 Kugan Vivekanandarajah * 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 index 00000000000..b84a9a83c50 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/init_char_with_nonchar_ctr.f90 @@ -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 -- 2.30.2