]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/77391 (gfortran allows CHARACTER(LEN=:),PARAMETER:: STRING...
authorSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 1 Oct 2016 04:58:02 +0000 (04:58 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 1 Oct 2016 04:58:02 +0000 (04:58 +0000)
2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>

Backport from trunk

PR fortran/77391
* resolve.c (deferred_requirements): New function to check F2008:C402.
(resolve_fl_variable,resolve_fl_parameter): Use it.

PR fortran/77391
* gfortran.dg/pr77391.f90: New test.

From-SVN: r240693

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr77391.f90 [new file with mode: 0644]

index ac34a8ae93fb3229d342d523b64f817dd4ef32ca..36855b858d7aebb32bd4ff137a36806851907a85 100644 (file)
@@ -1,3 +1,11 @@
+2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       Backport from trunk
+
+       PR fortran/77391
+       * resolve.c (deferred_requirements): New function to check F2008:C402.
+       (resolve_fl_variable,resolve_fl_parameter): Use it.
 2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from trunk
index 662c8707efb2cda2c526b7f2d6644070d24ed492..185cbab91ca58855f121f850b0adbe1f0120f3fa 100644 (file)
@@ -11214,6 +11214,27 @@ resolve_fl_variable_derived (gfc_symbol *sym, int no_init_flag)
 }
 
 
+/* F2008, C402 (R401):  A colon shall not be used as a type-param-value
+   except in the declaration of an entity or component that has the POINTER
+   or ALLOCATABLE attribute.  */
+
+static bool
+deferred_requirements (gfc_symbol *sym)
+{
+  if (sym->ts.deferred
+      && !(sym->attr.pointer
+          || sym->attr.allocatable
+          || sym->attr.omp_udr_artificial_var))
+    {
+      gfc_error ("Entity %qs at %L has a deferred type parameter and "
+                "requires either the POINTER or ALLOCATABLE attribute",
+                sym->name, &sym->declared_at);
+      return false;
+    }
+  return true;
+}
+
+
 /* Resolve symbols with flavor variable.  */
 
 static bool
@@ -11253,17 +11274,8 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag)
     }
 
   /* Constraints on deferred type parameter.  */
-  if (sym->ts.deferred
-      && !(sym->attr.pointer
-          || sym->attr.allocatable
-          || sym->attr.omp_udr_artificial_var))
-    {
-      gfc_error ("Entity %qs at %L has a deferred type parameter and "
-                "requires either the pointer or allocatable attribute",
-                    sym->name, &sym->declared_at);
-      specification_expr = saved_specification_expr;
-      return false;
-    }
+  if (!deferred_requirements (sym))
+    return false;
 
   if (sym->ts.type == BT_CHARACTER)
     {
@@ -13214,6 +13226,10 @@ resolve_fl_parameter (gfc_symbol *sym)
       return false;
     }
 
+  /* Constraints on deferred type parameter.  */
+  if (!deferred_requirements (sym))
+    return false;
+
   /* Make sure a parameter that has been implicitly typed still
      matches the implicit type, since PARAMETER statements can precede
      IMPLICIT statements.  */
index 02aa71655f08e7f1d6a4586ba0ca7b4ef0f60577..51b886b7a7a5d17050f199ff6f86b976b763b21a 100644 (file)
@@ -1,3 +1,10 @@
+2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       Backport from trunk
+
+       PR fortran/77391
+       * gfortran.dg/pr77391.f90: New test.
+
 2016-09-30  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        Backport from trunk
diff --git a/gcc/testsuite/gfortran.dg/pr77391.f90 b/gcc/testsuite/gfortran.dg/pr77391.f90
new file mode 100644 (file)
index 0000000..b3a455a
--- /dev/null
@@ -0,0 +1,7 @@
+! { dg-do compile }
+program picky
+character(len=:), parameter :: a="whoops" ! { dg-error "POINTER or ALLOCATABLE" }
+character(len=:) :: b="whoops" ! { dg-error "POINTER or ALLOCATABLE" }
+character(len=:) :: good
+pointer good
+end program picky