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