diff mbox

[fortran] Fix PR 65542, accepts invalid F95

Message ID 67362d4f-7bc4-0000-8b2c-ffd274f503ff@netcologne.de
State New
Headers show

Commit Message

Thomas Koenig Feb. 8, 2017, 9:17 p.m. UTC
Hello world,

the attached patch fixes a 5/6/7 regression where we accept
code that is invalid for F95.  Regression-tested.

OK for trunk?

(For some reason attaching the file doesn't work, and I don't want to
reboot my computer or log out just now because of some long-running
calculation. Therefore, I'm pasting both patch and test file.)


Regards

	Thomas

2017-02-08  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-08  Thomas Koenig  <tkoenig@gcc.gnu.org>

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

Patch:

    gfc_current_intrinsic_where = &expr->where;

    /* Bypass the generic list for min, max and ISO_C_Binding's c_loc.  */

Test case:

! { dg-do compile }
! { dg-options "-std=f95" }
! PR fortran/65542 - this did not give an error.
module bug
   integer :: ibug(42) = spread(42, 1, 42) ! { dg-error "invalid as 
initialization expression" }
end module

Comments

Steve Kargl Feb. 11, 2017, 4:49 p.m. UTC | #1
On Wed, Feb 08, 2017 at 10:17:10PM +0100, Thomas Koenig wrote:
> +         && !gfc_notify_std (GFC_STD_F2003, "Transformational function 
> %qs "
> +                             "invalid as initialization expression is 
> at %L",
> +                             name, &expr->where))

OK after you fix the error message.

Transformational function %qs at %L is invalid in an 
ininitialization expression
diff mbox

Patch

Index: intrinsic.c
===================================================================
--- intrinsic.c (Revision 244747)
+++ intrinsic.c (Arbeitskopie)
@@ -4680,6 +4680,27 @@  gfc_intrinsic_func_interface (gfc_expr *expr, int
        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 "
+                             "invalid as initialization expression is 
at %L",
+                             name, &expr->where))
+       {
+         if (!error_flag)
+           gfc_pop_suppress_errors ();
+
+         return MATCH_ERROR;
+       }
+    }
+