Blame SOURCES/0012-Allow-old-style-initializers-in-derived-types.patch

840d93
From 5d5a6c9d8c5a8db252d972ec32dd70d2510404fb Mon Sep 17 00:00:00 2001
840d93
From: Jim MacArthur <jim.macarthur@codethink.co.uk>
840d93
Date: Thu, 4 Feb 2016 16:00:30 +0000
840d93
Subject: [PATCH 12/23] Allow old-style initializers in derived types
840d93
840d93
This allows simple declarations in derived types and structures, such as:
840d93
    LOGICAL*1      NIL      /0/
840d93
Only single value expressions are allowed at the moment.
840d93
840d93
This feature is enabled by the `-std=extra-legacy` compiler flag.
840d93
---
840d93
840d93
commit a9ee9b2c45580d0e52670cec4d3d68095dabc178
840d93
Author: Jim MacArthur <jim.macarthur@codethink.co.uk>
840d93
Date:   Thu Feb 4 16:00:30 2016 +0000
840d93
840d93
    Allow old-style initializers in derived types
840d93
    
840d93
    This allows simple declarations in derived types and structures, such as:
840d93
        LOGICAL*1      NIL      /0/
840d93
    Only single value expressions are allowed at the moment.
840d93
    
840d93
    This feature is enabled by the `-std=extra-legacy` compiler flag.
840d93
    
840d93
    Test written by: Francisco Redondo Marchena <francisco.marchena@codethink.co.uk>
840d93
840d93
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
840d93
index c90f9de5a78..3ad9c2c8b40 100644
840d93
--- a/gcc/fortran/decl.c
840d93
+++ b/gcc/fortran/decl.c
840d93
@@ -2437,12 +2437,30 @@ variable_decl (int elem)
840d93
          but not components of derived types.  */
840d93
       else if (gfc_current_state () == COMP_DERIVED)
840d93
 	{
840d93
-	  gfc_error ("Invalid old style initialization for derived type "
840d93
-		     "component at %C");
840d93
-	  m = MATCH_ERROR;
840d93
-	  goto cleanup;
840d93
-	}
840d93
+	  if (gfc_option.allow_std & GFC_STD_EXTRA_LEGACY)
840d93
+	    {
840d93
+	      /* Attempt to match an old-style initializer which is a simple
840d93
+		 integer or character expression; this will not work with
840d93
+		 multiple values. */
840d93
+	      m = gfc_match_init_expr (&initializer);
840d93
+	      if (m == MATCH_ERROR)
840d93
+		goto cleanup;
840d93
+	      else if (m == MATCH_YES)
840d93
+		{
840d93
+		  m = gfc_match ("/");
840d93
+		  if (m != MATCH_YES)
840d93
+		    goto cleanup;
840d93
+		}
840d93
+	    }
840d93
+	  else
840d93
 
840d93
+	    {
840d93
+	      gfc_error ("Invalid old style initialization for derived type "
840d93
+			 "component at %C");
840d93
+	      m = MATCH_ERROR;
840d93
+	      goto cleanup;
840d93
+	    }
840d93
+	}
840d93
       /* For structure components, read the initializer as a special
840d93
          expression and let the rest of this function apply the initializer
840d93
          as usual.  */
840d93
diff --git a/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style.f b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style.f
840d93
new file mode 100644
840d93
index 00000000000..eac7de987e8
840d93
--- /dev/null
840d93
+++ b/gcc/testsuite/gfortran.dg/dec_derived_types_initialised_old_style.f
840d93
@@ -0,0 +1,22 @@
840d93
+! { dg-do compile }
840d93
+! { dg-options "-std=extra-legacy" }
840d93
+!
840d93
+! Test old style initializers in derived types
840d93
+!
840d93
+        PROGRAM spec_in_var
840d93
+          TYPE STRUCT1
840d93
+            INTEGER*4      ID       /8/
840d93
+            INTEGER*4      TYPE     /5/
840d93
+            INTEGER*8      DEFVAL   /0/
840d93
+            CHARACTER*(5)  NAME     /'tests'/
840d93
+            LOGICAL*1      NIL      /0/
840d93
+          END TYPE STRUCT1
840d93
+
840d93
+          TYPE (STRUCT1) SINST
840d93
+
840d93
+          if(SINST%ID.NE.8) STOP 1
840d93
+          if(SINST%TYPE.NE.5) STOP 2
840d93
+          if(SINST%DEFVAL.NE.0) STOP 3
840d93
+          if(SINST%NAME.NE.'tests') STOP 4
840d93
+          if(SINST%NIL) STOP 5
840d93
+        END