From: Thomas Koenig Date: Tue, 1 Aug 2017 19:09:02 +0000 (+0000) Subject: re PR fortran/79312 (Empty array in assignment not correctly type-checked) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d8afd032fad763a31efe2da716da657bde7c556b;p=gcc.git re PR fortran/79312 (Empty array in assignment not correctly type-checked) 2017-08-01 Thomas König PR fortran/79312 * intrisic.c (gfc_convert_type_warn): Only set typespec for empty array constructors which don't have it already. 2017-08-01 Thomas König PR fortran/79312 * gfortran.dg/logical_assignment_1.f90: New test. From-SVN: r250792 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bd9ecc348f4..7c10d8c59f3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2017-08-01 Thomas König + + PR fortran/79312 + * intrisic.c (gfc_convert_type_warn): Only set typespec for + empty array constructors which don't have it already. + 2017-08-01 Thomas Koenig PR fortran/45435 diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index 2f60fe8c877..8965d509882 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -4919,9 +4919,11 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag) if (ts->type == BT_UNKNOWN) goto bad; - /* NULL and zero size arrays get their type here. */ - if (expr->expr_type == EXPR_NULL - || (expr->expr_type == EXPR_ARRAY && expr->value.constructor == NULL)) + /* NULL and zero size arrays get their type here, unless they already have a + typespec. */ + if ((expr->expr_type == EXPR_NULL + || (expr->expr_type == EXPR_ARRAY && expr->value.constructor == NULL)) + && expr->ts.type == BT_UNKNOWN) { /* Sometimes the RHS acquire the type. */ expr->ts = *ts; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 53081a7c330..3ba6bb98070 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-08-01 Thomas König + + PR fortran/79312 + * gfortran.dg/logical_assignment_1.f90: New test. + 2017-08-01 Martin Liska PR middle-end/70140 diff --git a/gcc/testsuite/gfortran.dg/logical_assignment_1.f90 b/gcc/testsuite/gfortran.dg/logical_assignment_1.f90 new file mode 100644 index 00000000000..c2289805118 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/logical_assignment_1.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR 79312 - assigning a logical value to a real +! is invalid. +! Test case by John Harper. +program emptyarray5 + implicit none + real a(0) + a = [logical::] ! { dg-error "Can't convert LOGICAL" } + print *,size(a) +end program emptyarray5