public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, libfortran] PR95647 operator(.eq.) and operator(==) treated differently
@ 2021-02-12  3:02 Jerry DeLisle
  2021-02-12  7:50 ` Tobias Burnus
  2021-02-12 16:35 ` Jerry DeLisle
  0 siblings, 2 replies; 3+ messages in thread
From: Jerry DeLisle @ 2021-02-12  3:02 UTC (permalink / raw)
  To: gfortran; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 756 bytes --]

The attached patch is another provided from Steve Kargle in the PR report.

I have created a test case and regression tested the result.

OK for trunk?

Regards,

Jerry

libgfortran: Fix PR95647 by changing the interfaces of operators .eq. 
and .ne.

The FE converts the old school .eq. to ==,
and then tracks the ==.  The module starts with == and so it does not
properly overload the .eq.  Reversing the interfaces fixes this.

2021-02-11  Steve Kargl <sgk@troutmask.apl.washington.edu>

libgfortran/ChangeLog:

     PR libfortran 95647
     * ieee/ieee_arithmetic.F90: Flip interfaces of operators .eq. to
     == and .ne. to /= .

gcc/testsuite/ChangeLog:

     PR libfortran 95647
     * gfortran.dg/ieee/ieee_arithmetic: New test.


[-- Attachment #2: pr95647.diff --]
[-- Type: text/x-patch, Size: 1915 bytes --]

diff --git a/gcc/testsuite/gfortran.dg/ieee/ieee_12.f90 b/gcc/testsuite/gfortran.dg/ieee/ieee_12.f90
new file mode 100644
index 00000000000..139a70142b8
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/ieee/ieee_12.f90
@@ -0,0 +1,24 @@
+! { dg-do run }
+! PR95647 operator(.eq.) and operator(==) treated differently
+program test
+  use, intrinsic :: ieee_arithmetic, only :                 &
+&                ieee_class,                                       &
+&                ieee_class_type,                                  &
+&                ieee_negative_normal,                             &
+&                ieee_positive_normal,                             &
+&                operator(.eq.), operator(.ne.)
+  integer :: good
+  real(4) r4
+  type(ieee_class_type) class1
+  good = 0
+  r4 = 1.0
+  class1 = ieee_class(r4)
+  if (class1 .eq. ieee_positive_normal) good = good + 1
+  if (class1 .ne. ieee_negative_normal) good = good + 1
+  r4 = -1.0
+  class1 = ieee_class(r4)
+  if (class1 .eq. ieee_negative_normal) good = good + 1
+  if (class1 .ne. ieee_positive_normal) good = good + 1
+  if (good /= 4) call abort
+end program test
+
diff --git a/libgfortran/ieee/ieee_arithmetic.F90 b/libgfortran/ieee/ieee_arithmetic.F90
index 55992232ce2..35a16938f8e 100644
--- a/libgfortran/ieee/ieee_arithmetic.F90
+++ b/libgfortran/ieee/ieee_arithmetic.F90
@@ -77,15 +77,16 @@ module IEEE_ARITHMETIC
 
 
   ! Equality operators on the derived types
-  interface operator (==)
+  ! Note, the FE overloads .eq. to == and .ne. to /=
+  interface operator (.eq.)
     module procedure IEEE_CLASS_TYPE_EQ, IEEE_ROUND_TYPE_EQ
   end interface
-  public :: operator(==)
+  public :: operator(.eq.)
 
-  interface operator (/=)
+  interface operator (.ne.)
     module procedure IEEE_CLASS_TYPE_NE, IEEE_ROUND_TYPE_NE
   end interface
-  public :: operator (/=)
+  public :: operator (.ne.)
 
 
   ! IEEE_IS_FINITE

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-12 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-12  3:02 [patch, libfortran] PR95647 operator(.eq.) and operator(==) treated differently Jerry DeLisle
2021-02-12  7:50 ` Tobias Burnus
2021-02-12 16:35 ` Jerry DeLisle

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).