From 5fc813ec3cfc4fd0741fc3ce56912f6b240894e2 Mon Sep 17 00:00:00 2001
From: bdavis <bdavis@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Fri, 24 Dec 2004 00:29:07 +0000
Subject: [PATCH] 2004-12-23  Bud Davis  <bdavis9659@comcast.net>

        PR fortran/19071
        * io/tranfer.c (formatted_transfer): moved check for
        format reversion inside the processing loop.

        * gfortran.dg/complex_write.f90: New test.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@92582 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/testsuite/ChangeLog                     |  5 +++++
 gcc/testsuite/gfortran.dg/complex_write.f90 | 15 +++++++++++++++
 libgfortran/ChangeLog                       |  6 ++++++
 libgfortran/io/transfer.c                   | 16 ++++++++--------
 4 files changed, 34 insertions(+), 8 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/complex_write.f90

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6e3c26251f05..f504598b9fe1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-23  Bud Davis  <bdavis9659@comcast.net>
+
+	PR fortran/19071
+	* gfortran.dg/complex_write.f90: New test.
+ 
 2004-12-23  Mark Mitchell  <mark@codesourcery.com>
 
 	PR c++/17595
diff --git a/gcc/testsuite/gfortran.dg/complex_write.f90 b/gcc/testsuite/gfortran.dg/complex_write.f90
new file mode 100644
index 000000000000..3b73ba3a023b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/complex_write.f90
@@ -0,0 +1,15 @@
+! { dg-do run }
+! pr 19071
+! test case provided by
+!   Thomas.Koenig@online.de
+       program cio      
+       complex a      
+       real r1,r2      
+       a = cmplx(1.0, 2.0)      
+       open(unit=74,status='scratch')      
+       write(74,'(1P,E13.5)'),a      
+       rewind(74)
+!  can read the complex in as two reals, one on each line
+       read(74,'(E13.5)')r1,r2      
+       if (r1.ne.1.0 .and. r2.ne.2.0) call abort
+       end
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 452bb4aa76c1..749f5a3edbed 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,9 @@
+2004-12-23  Bud Davis  <bdavis9659@comcast.net>
+
+	PR fortran/19071
+	* io/tranfer.c (formatted_transfer): moved check for 
+	format reversion inside the processing loop.
+
 2004-12-19  Aaron W. LaFramboise  <aaronavay62@aaronwl.com>
 
 	PR libfortran/19074
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index c3daa21bfacf..fb673042432f 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -425,16 +425,16 @@ formatted_transfer (bt type, void *p, int len)
   if (type == BT_COMPLEX)
     type = BT_REAL;
 
-  /* If reversion has occurred and there is another real data item,
-     then we have to move to the next record.  */
-
-  if (g.reversion_flag && n > 0)
-    {
-      g.reversion_flag = 0;
-      next_record (0);
-    }
   for (;;)
     {
+      /* If reversion has occurred and there is another real data item,
+         then we have to move to the next record.  */
+      if (g.reversion_flag && n > 0)
+        {
+          g.reversion_flag = 0;
+          next_record (0);
+        }
+
       consume_data_flag = 1 ;
       if (ioparm.library_return != LIBRARY_OK)
 	break;
-- 
GitLab