The attach patch re-arranges code to permit gfortran to issue
an error message under non-gnu -std=* options when an entity
appears in a double initialization.  Prior to this patch,
the new testcase pr78278.f90 would compile without error.
Regression tested on x86_64-*-freebsd.  OK to commit?

2018-06-08  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/78278
        * data.c (gfc_assign_data_value): Re-arrange code to allow for
        an error for double initialization of CHARACTER entities.

2018-06-08  Steven G. Kargl  <ka...@gcc.gnu.org>

        PR fortran/78278
        * gfortran.dg/data_bounds_1.f90: Add -std=gnu option.
        * gfortran.dg/data_char_1.f90: Ditto.
        * gfortran.dg/pr78571.f90: Ditto.
        * gfortran.dg/pr78278.f90: New test.

-- 
Steve
Index: gcc/fortran/data.c
===================================================================
--- gcc/fortran/data.c	(revision 261343)
+++ gcc/fortran/data.c	(working copy)
@@ -483,6 +483,21 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rva
   mpz_clear (offset);
   gcc_assert (repeat == NULL);
 
+  /* Overwriting an existing initializer is non-standard but usually only
+     provokes a warning from other compilers.  */
+  if (init != NULL && init->where.lb && rvalue->where.lb)
+    {
+      /* Order in which the expressions arrive here depends on whether
+	 they are from data statements or F95 style declarations.
+	 Therefore, check which is the most recent.  */
+      expr = (LOCATION_LINE (init->where.lb->location)
+	      > LOCATION_LINE (rvalue->where.lb->location))
+	   ? init : rvalue;
+      if (gfc_notify_std (GFC_STD_GNU, "re-initialization of %qs at %L",
+			  symbol->name, &expr->where) == false)
+	return false;
+    }
+
   if (ref || last_ts->type == BT_CHARACTER)
     {
       /* An initializer has to be constant.  */
@@ -501,22 +516,6 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rva
 		     "shall not appear in a DATA statement at %L", 
 		     symbol->name, &lvalue->where);
 	  return false;
-	}
-
-      /* Overwriting an existing initializer is non-standard but usually only
-	 provokes a warning from other compilers.  */
-      if (init != NULL)
-	{
-	  /* Order in which the expressions arrive here depends on whether
-	     they are from data statements or F95 style declarations.
-	     Therefore, check which is the most recent.  */
-	  expr = (LOCATION_LINE (init->where.lb->location)
-		  > LOCATION_LINE (rvalue->where.lb->location))
-	       ? init : rvalue;
-	  if (gfc_notify_std (GFC_STD_GNU,
-			      "re-initialization of %qs at %L",
-			      symbol->name, &expr->where) == false)
-	    return false;
 	}
 
       expr = gfc_copy_expr (rvalue);
Index: gcc/testsuite/gfortran.dg/data_bounds_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/data_bounds_1.f90	(revision 261342)
+++ gcc/testsuite/gfortran.dg/data_bounds_1.f90	(working copy)
@@ -1,4 +1,5 @@
 ! { dg-do compile }
+! { dg-options "-std=gnu" }
 ! Checks the fix for PR32315, in which the bounds checks below were not being done.
 !
 ! Contributed by Tobias Burnus <bur...@gcc.gnu.org>
Index: gcc/testsuite/gfortran.dg/data_char_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/data_char_1.f90	(revision 261342)
+++ gcc/testsuite/gfortran.dg/data_char_1.f90	(working copy)
@@ -1,4 +1,5 @@
 ! { dg-do run }
+! { dg-options "-std=gnu" }
 ! Test character variables in data statements
 ! Also substrings of character variables.
 ! PR14976 PR16228 
Index: gcc/testsuite/gfortran.dg/pr78278.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr78278.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr78278.f90	(working copy)
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! { dg-options "-std=f95" }
+! PR fortran/78278
+program p
+   character, pointer :: x => null()
+   data x /null()/         ! { dg-error "GNU Extension: re-initialization" }
+   print *, associated(x)
+end
+
+subroutine foo
+   real :: x = 42
+   data x /0/              ! { dg-error "GNU Extension: re-initialization" }
+   print *, x
+end subroutine foo
Index: gcc/testsuite/gfortran.dg/pr78571.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr78571.f90	(revision 261343)
+++ gcc/testsuite/gfortran.dg/pr78571.f90	(working copy)
@@ -1,4 +1,5 @@
 ! { dg-do compile }
+! { dg-options "-std=gnu" }
 ! PR fortran/78571
 program p
    type t

Reply via email to