re PR fortran/91660 (Missing error on invalid type declaration)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Thu, 5 Sep 2019 18:14:34 +0000 (18:14 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Thu, 5 Sep 2019 18:14:34 +0000 (18:14 +0000)
2019-09-05  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/91660
* decl.c (gfc_match_decl_type_spec): Improve and restore error
message for malformed types-spec.

2019-09-05  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/91660
* gfortran.dg/pdt_4.f03: Fix invalid code.
* gfortran.dg/pr91660_1.f90: New test.
* gfortran.dg/pr91660_2.f90: Ditto.

From-SVN: r275426

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pdt_4.f03
gcc/testsuite/gfortran.dg/pr91660_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr91660_2.f90 [new file with mode: 0644]

index 4da49108c9de60ed57fbcb307d8967e885479c8d..129bfdd9ae741f02f6e7f9bb47a3c539c0187931 100644 (file)
@@ -1,3 +1,9 @@
+2019-09-05  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/91660
+       * decl.c (gfc_match_decl_type_spec): Improve and restore error
+       message for malformed types-spec.
+
 2019-09-04  Steven G. Kargl  <kargl@gcvc.gnu.org>
 
        PR fortran/91650
index 071119157d6dafd746da88d0b68e2e888a32f4ff..278882d985562bd4ee9a832458af12b3b2543ec7 100644 (file)
@@ -4023,7 +4023,6 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
       return MATCH_YES;
     }
 
-
   m = gfc_match (" type (");
   matched_type = (m == MATCH_YES);
   if (matched_type)
@@ -4071,7 +4070,10 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
        m = MATCH_YES;
 
       if (matched_type && m == MATCH_YES && gfc_match_char (')') != MATCH_YES)
-       m = MATCH_ERROR;
+       {
+         gfc_error ("Malformed type-spec at %C");
+         return MATCH_ERROR;
+       }
 
       return m;
     }
@@ -4094,8 +4096,12 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
          && !gfc_notify_std (GFC_STD_F2008, "TYPE with "
                              "intrinsic-type-spec at %C"))
        return MATCH_ERROR;
+
       if (matched_type && gfc_match_char (')') != MATCH_YES)
-       return MATCH_ERROR;
+       {
+         gfc_error ("Malformed type-spec at %C");
+         return MATCH_ERROR;
+       }
 
       ts->type = BT_REAL;
       ts->kind = gfc_default_double_kind;
@@ -4125,7 +4131,10 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
        return MATCH_ERROR;
 
       if (matched_type && gfc_match_char (')') != MATCH_YES)
-       return MATCH_ERROR;
+       {
+         gfc_error ("Malformed type-spec at %C");
+         return MATCH_ERROR;
+       }
 
       ts->type = BT_COMPLEX;
       ts->kind = gfc_default_double_kind;
@@ -4146,7 +4155,13 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implicit_flag)
       if (m == MATCH_ERROR)
        return m;
 
-    m = gfc_match_char (')');
+      gfc_gobble_whitespace ();
+      if (gfc_peek_ascii_char () != ')')
+       {
+         gfc_error ("Malformed type-spec at %C");
+         return MATCH_ERROR;
+       }
+      m = gfc_match_char (')'); /* Burn closing ')'.  */
     }
 
   if (m != MATCH_YES)
index 9940cec8879759f0087bd6e50724dffd9b432140..a43cec3e282b969c059ae3b1878d25efb940cd36 100644 (file)
@@ -1,3 +1,10 @@
+2019-09-05  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/91660
+       * gfortran.dg/pdt_4.f03: Fix invalid code.
+        * gfortran.dg/pr91660_1.f90: New test.
+       * gfortran.dg/pr91660_2.f90: Ditto.
+
 2019-09-05  Marek Polacek  <polacek@redhat.com>
 
        PR c++/91644 - ICE with constinit in function template.
index 0bb58f91c67d60bd9dfe4052b06f78a314ac9c79..c1af65a52487361ba9d361a043d3e1fe0d943146 100644 (file)
@@ -97,9 +97,9 @@ contains
     type (mytype(4, *)) :: arg      ! OK
   end subroutine
   subroutine bar(arg)               ! { dg-error "is neither allocatable nor a pointer" }
-    type (thytype(8, :, 4) :: arg
+    type (thytype(8, :, 4)) :: arg
   end subroutine
   subroutine foobar(arg)            ! OK
-    type (thytype(8, *, 4) :: arg
+    type (thytype(8, *, 4)) :: arg
   end subroutine
 end
diff --git a/gcc/testsuite/gfortran.dg/pr91660_1.f90 b/gcc/testsuite/gfortran.dg/pr91660_1.f90
new file mode 100644 (file)
index 0000000..53a1a80
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/91660
+! Code contributed by Gerhard Steinmetz
+program p
+   type t
+   end type
+   type (t x    ! { dg-error "Malformed type-spec" }
+   x = t()      ! { dg-error "Cannot convert" }
+end
diff --git a/gcc/testsuite/gfortran.dg/pr91660_2.f90 b/gcc/testsuite/gfortran.dg/pr91660_2.f90
new file mode 100644 (file)
index 0000000..0072aba
--- /dev/null
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/91660
+program foo
+   type(doubleprecision :: x   ! { dg-error "Malformed type-spec" }
+   type(double precision :: y  ! { dg-error "Malformed type-spec" }
+   type(character(len=3) :: a  ! { dg-error "Malformed type-spec" }
+   type(doublecomplex :: b     ! { dg-error "Malformed type-spec" }
+   type(double complex :: c    ! { dg-error "Malformed type-spec" }
+end program foo