From: Steven G. Kargl Date: Sat, 9 Jun 2018 15:58:24 +0000 (+0000) Subject: re PR fortran/38351 (Poor error message for rank mismatch in operator args) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1dd88f8beedd63cd957edcdf2a28f7b76dfc583a;p=gcc.git re PR fortran/38351 (Poor error message for rank mismatch in operator args) 2018-06-09 Steven G. Kargl PR fortran/38351 * resolve.c (resolve_operator): Provide better error message for derived type entity used in an binary intrinsic numeric operator. 2018-06-09 Steven G. Kargl PR fortran/38351 * gfortran.dg/pr38351.f90: New test. * gfortran.dg/typebound_operator_4.f03: Adjust for new error message. From-SVN: r261363 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 1868780c921..7bfeac1c8aa 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2018-06-09 Steven G. Kargl + + PR fortran/38351 + * resolve.c (resolve_operator): Provide better error message for + derived type entity used in an binary intrinsic numeric operator. + 2018-06-09 Steven G. Kargl PR fortran/85138 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 3d53ce56699..b1d4e032773 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -3878,7 +3878,13 @@ resolve_operator (gfc_expr *e) break; } - sprintf (msg, + if (op1->ts.type == BT_DERIVED || op2->ts.type == BT_DERIVED) + sprintf (msg, + _("Unexpected derived-type entities in binary intrinsic " + "numeric operator %%<%s%%> at %%L"), + gfc_op2string (e->value.op.op)); + else + sprintf (msg, _("Operands of binary numeric operator %%<%s%%> at %%L are %s/%s"), gfc_op2string (e->value.op.op), gfc_typename (&op1->ts), gfc_typename (&op2->ts)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 135213b0f48..41e24e762ed 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-06-09 Steven G. Kargl + + PR fortran/38351 + * gfortran.dg/pr38351.f90: New test. + * gfortran.dg/typebound_operator_4.f03: Adjust for new error message. + 2018-06-09 Steven G. Kargl PR fortran/85138 diff --git a/gcc/testsuite/gfortran.dg/pr38351.f90 b/gcc/testsuite/gfortran.dg/pr38351.f90 new file mode 100644 index 00000000000..08e1724dc0a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr38351.f90 @@ -0,0 +1,21 @@ +! { dg-do compile } +module m1 + type t1 + integer :: i + end type t1 + interface operator(+) + module procedure add + end interface + contains + type(t1) function add(a,b) + type(t1), intent(in) :: a,b + end function +end module m1 + +program foo + use m1 + type(t1), dimension(2,2) :: a = t1(1), b = t1(2) + type(t1) :: c=t1(1), d=t1(2) + c = c + d + a = a + b ! { dg-error "Unexpected derived-type entities" } +end program foo diff --git a/gcc/testsuite/gfortran.dg/typebound_operator_4.f03 b/gcc/testsuite/gfortran.dg/typebound_operator_4.f03 index 836505bba3d..cd0e8f602ae 100644 --- a/gcc/testsuite/gfortran.dg/typebound_operator_4.f03 +++ b/gcc/testsuite/gfortran.dg/typebound_operator_4.f03 @@ -84,6 +84,6 @@ PROGRAM main TYPE(myint) :: x x = 0 ! { dg-error "Can't convert" } - x = x + 42 ! { dg-error "Operands of" } + x = x + 42 ! { dg-error "binary intrinsic numeric operator" } x = x .PLUS. 5 ! { dg-error "Unknown operator" } END PROGRAM main