* [Committed] PR fortran/38351 -- Improved error message
@ 2018-06-10 1:48 Steve Kargl
0 siblings, 0 replies; only message in thread
From: Steve Kargl @ 2018-06-10 1:48 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 544 bytes --]
I've committed the attached patch. It provides a better error
message (IMO) when a derived-type entity is used in a binary
intrinsic numeric operator.
2018-06-09 Steven G. Kargl <kargl@gcc.gnu.org>
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 <kargl@gcc.gnu.org>
PR fortran/38351
* gfortran.dg/pr38351.f90: New test.
* gfortran.dg/typebound_operator_4.f03: Adjust for new error message.
--
Steve
[-- Attachment #2: pr38351.diff --]
[-- Type: text/x-diff, Size: 1985 bytes --]
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 261361)
+++ gcc/fortran/resolve.c (working copy)
@@ -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));
Index: gcc/testsuite/gfortran.dg/pr38351.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr38351.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr38351.f90 (working copy)
@@ -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
Index: gcc/testsuite/gfortran.dg/typebound_operator_4.f03
===================================================================
--- gcc/testsuite/gfortran.dg/typebound_operator_4.f03 (revision 261361)
+++ gcc/testsuite/gfortran.dg/typebound_operator_4.f03 (working copy)
@@ -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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-06-09 16:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-10 1:48 [Committed] PR fortran/38351 -- Improved error message Steve Kargl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).