re PR fortran/65542 (SPREAD intrinsic incorrectly accepted in initialization expressi...
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 12 Feb 2017 16:10:22 +0000 (16:10 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 12 Feb 2017 16:10:22 +0000 (16:10 +0000)
2017-02-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/65542
* intrinsic.c (gfc_intrinsic_func_interface):  Return an error
for -std=f95 for disallowed transformational functions in
initialization expressions.

2017-02-12  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/65542
* gfortran.dg/spread_init_expr_2.f90:  New test case.

From-SVN: r245376

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

index 3488f01e7cdaa54bebbe8e342ddd1e2410f0eda1..dc5e50e9ab998cf2c54d8208b1a4889da5c57475 100644 (file)
@@ -1,3 +1,10 @@
+2017-02-12  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/65542
+       * intrinsic.c (gfc_intrinsic_func_interface):  Return an error
+       for -std=f95 for disallowed transformational functions in
+       initialization expressions.
+
 2017-02-09  Cesar Philippidis  <cesar@codesourcery.com>
            Joseph Myers  <joseph@codesourcery.com>
 
index e059a312dfdaf4af302dfc613030fea8792f3e3c..923572d888c44d6c176a9d1757c2bf50147d6133 100644 (file)
@@ -4680,6 +4680,27 @@ gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag)
       return MATCH_ERROR;
     }
 
+  /* F95, 7.1.6.1: Only transformational functions REPEAT, RESHAPE,
+     SELECTED_INT_KIND, SELECTED_REAL_KIND, TRANSFER, and TRIM are allowed in
+     initialization expressions.  */
+
+  if (gfc_init_expr_flag && isym->transformational)
+    {
+      gfc_isym_id id = isym->id;
+      if (id != GFC_ISYM_REPEAT && id != GFC_ISYM_RESHAPE
+         && id != GFC_ISYM_SI_KIND && id != GFC_ISYM_SR_KIND
+         && id != GFC_ISYM_TRANSFER && id != GFC_ISYM_TRIM
+         && !gfc_notify_std (GFC_STD_F2003, "Transformational function %qs "
+                             "at %L is invalid in an initialization "
+                             "expression", name, &expr->where))
+       {
+         if (!error_flag)
+           gfc_pop_suppress_errors ();
+
+         return MATCH_ERROR;
+       }
+    }
+
   gfc_current_intrinsic_where = &expr->where;
 
   /* Bypass the generic list for min, max and ISO_C_Binding's c_loc.  */
index cdec4d631f814e6a93c329ed8231e34633dfaa8f..429fe944fe32e785feb50d50c7a1cc8741b8f565 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-12  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/65542
+       * gfortran.dg/spread_init_expr_2.f90:  New test case.
+
 2017-02-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR sanitizer/79341
diff --git a/gcc/testsuite/gfortran.dg/spread_init_expr_2.f90 b/gcc/testsuite/gfortran.dg/spread_init_expr_2.f90
new file mode 100644 (file)
index 0000000..19c27fa
--- /dev/null
@@ -0,0 +1,5 @@
+! { dg-do compile }
+! { dg-options "-std=f95" }
+module bug
+  integer :: ibug(42) = spread(42, 1, 42) ! { dg-error "invalid in an initialization expression" }
+end module