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

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