[PATCH, Fortran] Extension: Support legacy PARAMETER statements with -std=legacy (or -fdec?)

Jerry DeLisle jvdelisle@charter.net
Wed Nov 2 19:38:00 GMT 2016


On 11/02/2016 08:47 AM, Fritz Reese wrote:
> All,
>
> Another quirk of legacy compilers is their syntax for PARAMETER
> statements. Such statements are similar to standard PARAMETER
> statements but lack parentheses following the PARAMETER keyword. There
> is a good reason the standard doesn't support this - because the
> statement becomes ambiguous with assignment statements in fixed form.
> Consider the following:
>
>         parameter pi = 3.14d0
>
> In fixed form, spaces are ignored so in standard Fortran the above
> looks like an assignment to the variable "parameterpi". In legacy
> compilers, the above is instead interpreted as
>
>         parameter (pi = 3.14d0)
>
> which of course declares the variable 'pi' to be a parameter with the
> value 3.14.
>
> Attached is a patch for the GNU Fortran front-end which allows the
> compiler to interpret these legacy PARAMETER statements. The patch in
> its current form does this without warning through -std=legacy
> (warning for -std=gnu, error for -std=f*). Bootstraps and regtests on
> x86_64-redhat-linux.
>
> However, note that this would change by default the compiler's
> interpretation of fixed-form variables starting with the string
> "parameter", if any such cases existed in real code. IMO fixed form
> code is isomorphic to legacy code, so I imagine most users writing
> fixed-form/legacy code would intend for a legacy PARAMETER statement,
> rather than assignment to variable PARAMETERPI, when writing such a
> statement.
>
> Beyond compatibility, one motivation for acceptance/recognizance of
> these statements in GNU Fortran is the counterintuitive compile errors
> currently seen when compiling legacy code which uses this type of
> statement. Because the legacy PARAMETER statement is currently
> interpreted as an assignment in fixed-form, and parameter statements
> often precede other specification statements in real code, GNU Fortran
> complains not about the parameter statement itself but often the
> following line with "Unexpected data declaration" or similar. This
> serves to confuse the user. An example of this can be seen by
> compiling the attached dec_parameter_1.f in fixed form with the
> current build of GNU Fortran.
>
> I am amenable to only enabling support for legacy PARAMETER statements
> through -fdec, so that the default (-std=gnu) behavior is unchanged
> for such cases in fixed form. But this would leave the esoteric
> "Unexpected data declaration statement" errors for legacy code without
> -fdec. The case would be difficult to detect and work around
> specifically since the entire parameter "assignment" statement is
> eaten by the time the error comes about.
>
> What do you think?
>

How does the behavior compare to G77 current behavior. Often we use -std=legacy 
to maintain compatibility with G77, so we do not want to break anything there, 
though I realize we can not be perfect in all cases.

Jerry



More information about the Fortran mailing list