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