]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran : "type is( real(kind(1.)) )" spurious syntax error PR94397
authorMark Eggleston <markeggleston@gcc.gnu.org>
Wed, 1 Apr 2020 08:52:41 +0000 (09:52 +0100)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Thu, 28 May 2020 14:12:33 +0000 (15:12 +0100)
Based on a patch in the comments of the PR. That patch fixed this
problem but caused the test cases for PR93484 to fail. It has been
changed to reduce initialisation expressions if the expression is
not EXPR_VARIABLE and not EXPR_CONSTANT.

2020-05-28  Steven G. Kargl  <kargl@gcc.gnu.org>
    Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/fortran/

PR fortran/94397
* match.c (gfc_match_type_spec): New variable ok initialised
to true. Set ok with the return value of gfc_reduce_init_expr
called only if the expression is not EXPR_CONSTANT and is not
EXPR_VARIABLE. Add !ok to the check for type not being integer
or the rank being greater than zero.

2020-05-28  Mark Eggleston  <markeggleston@gcc.gnu.org>

gcc/testsuite/

PR fortran/94397
* gfortran.dg/pr94397.F90: New test.

(cherry picked from commit 3ea6977d0f1813d982743a09660eec1760e981ec)

gcc/fortran/match.c
gcc/testsuite/gfortran.dg/pr94397.F90 [new file with mode: 0644]

index f4ae9e9dfe75325c91a28609989c62e941f77675..11989295b0dbd4db4d7eac4d5cdb715f7377bb11 100644 (file)
@@ -2217,7 +2217,10 @@ found:
         a scalar integer initialization-expr and valid kind parameter. */
       if (c == ')')
        {
-         if (e->ts.type != BT_INTEGER || e->rank > 0)
+         bool ok = true;
+         if (e->expr_type != EXPR_CONSTANT && e->expr_type != EXPR_VARIABLE)
+           ok = gfc_reduce_init_expr (e);
+         if (!ok || e->ts.type != BT_INTEGER || e->rank > 0)
            {
              gfc_free_expr (e);
              return MATCH_NO;
diff --git a/gcc/testsuite/gfortran.dg/pr94397.F90 b/gcc/testsuite/gfortran.dg/pr94397.F90
new file mode 100644 (file)
index 0000000..fda10c1
--- /dev/null
@@ -0,0 +1,26 @@
+! { dg-do run }
+!
+
+module m
+  implicit none
+contains
+  function is_real8(a)
+    class(*) :: a
+    logical :: is_real8
+    is_real8 = .false.
+    select type(a)
+      type is(real(kind(1.0_8)))
+        is_real8 = .true. 
+    end select
+  end function is_real8
+end module m
+
+program test
+  use m
+
+  if (is_real8(1.0_4)) stop 1
+  if (.not. is_real8(1.0_8)) stop 2
+#ifdef __GFC_REAL_16__
+  if (is_real8(1.0_16)) stop 3
+#endif
+end program