This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] PR13910 Old-style initialization of LOGICAL variables



This adds a very restricted language extension.


Bud reported that it is commonplace in some codes to initialize LOGICALs as follows:
LOGICAL L / .TRUE. /


This patch allows this, if we're compiling with STD_GNU. Compile testcase attached.

Bootstrapped and regtested. This has been in my tree for a while and caused no problems.

- Tobi

2004-05-11 Tobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/13910
	* decl.c: Update copyright years. Include system.h and flags.h.
	Reorder includes to match other files.
	(variable_decl): Allow old-style initialization of LOGICALS.

Index: decl.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/Attic/decl.c,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 decl.c
--- decl.c      2 Aug 2003 00:26:48 -0000       1.1.2.2
+++ decl.c      11 May 2004 19:36:42 -0000
@@ -1,5 +1,5 @@
 /* Declaration statement matcher
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004 Free Software Foundation, Inc.
    Contributed by Andy Vaught

 This file is part of GNU G95.
@@ -21,10 +21,14 @@ Boston, MA 02111-1307, USA.  */


#include "config.h" +#include "system.h" +#include "flags.h" + +#include <string.h> + #include "gfortran.h" #include "match.h" #include "parse.h" -#include <string.h>


/* This flag is set if a an old-style length selector is matched @@ -556,9 +569,52 @@ variable_decl (void) goto cleanup; }

+ /* Allow non-standard old style initialization of the form:
+ LOGICAL l /.TRUE./
+ In order to not introduce an overly complex extension, this is
+ fairly restricted: we only allow this for non-pointer variables,
+ and only if no colon has been seen, i.e.
+ LOGICAL :: l /.TRUE./
+ is not allowed. */
+ if (!colon_seen)
+ {
+ if (gfc_match (" /") == MATCH_YES)
+ {
+ if (current_attr.pointer)
+ {
+ gfc_error("Pointer initialization at %C requires '=>'");
+ m = MATCH_ERROR;
+ goto cleanup;
+ }
+
+ m = gfc_match_init_expr (&initializer);
+ if (m == MATCH_NO)
+ {
+ gfc_error ("Expected an initialization expression at %C");
+ m = MATCH_ERROR;
+ }
+
+ if (current_attr.flavor != FL_PARAMETER && gfc_pure (NULL))
+ {
+ gfc_error
+ ("Initialization of variable at %C is not allowed in a "
+ "PURE procedure");
+ m = MATCH_ERROR;
+ }
+
+ m = gfc_match(" /");
+ if (m == MATCH_YES && pedantic)
+ if (gfc_notify_std (GFC_STD_GNU, "Extension: Old-style "
+ "initialization of LOGICAL at %C") == FAILURE)
+ m = MATCH_NO;
+
+ if (m != MATCH_YES)
+ goto cleanup;
+ }
+ }
/* The double colon must be present in order to have initializers.
Otherwise the statement is ambiguous with an assignment statement. */
- if (colon_seen)
+ else
{
if (gfc_match (" =>") == MATCH_YES)
{



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]